{"id":1114,"date":"2022-08-30T15:12:37","date_gmt":"2022-08-30T15:12:37","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/javascript-how-to-initialize-super-class-if-super-class-constructor-takes-arguments-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:12:37","modified_gmt":"2022-08-30T15:12:37","slug":"javascript-how-to-initialize-super-class-if-super-class-constructor-takes-arguments-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/javascript-how-to-initialize-super-class-if-super-class-constructor-takes-arguments-collection-of-common-programming-errors\/","title":{"rendered":"Javascript &#8211; how to initialize super class if super class constructor takes arguments-Collection of common programming errors"},"content":{"rendered":"<p>First of all, there&#8217;s a bunch of errors in that code.<\/p>\n<p>This will make IntermediateClass a <em>sister<\/em> of SuperClass.<\/p>\n<pre><code>IntermediateClass.prototype = SuperClass.prototype;\n<\/code><\/pre>\n<p>You never need to do this, <code>constructor<\/code> is handled for you.<\/p>\n<pre><code>SubClass.prototype.constructor = SubClass;\n<\/code><\/pre>\n<p>That said, JavaScript <em>doesn&#8217;t have classes<\/em>. Inheritance is object-based. You can&#8217;t do what you&#8217;re trying to do.<\/p>\n<p>Instead, I would extract the initialisation in a separate function, then call it from the &#8220;subclass&#8221;.<\/p>\n<p>A better question is what you&#8217;re trying to accomplish. You&#8217;re trying to write JavaScript as if it was Java. It&#8217;s not.<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 23:29:52. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>First of all, there&#8217;s a bunch of errors in that code. This will make IntermediateClass a sister of SuperClass. IntermediateClass.prototype = SuperClass.prototype; You never need to do this, constructor is handled for you. SubClass.prototype.constructor = SubClass; That said, JavaScript doesn&#8217;t have classes. Inheritance is object-based. You can&#8217;t do what you&#8217;re trying to do. Instead, I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1114","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1114"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1114\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}