Note that there are some explanatory texts on larger screens.

plurals
  1. POjavascript inheritance
    primarykey
    data
    text
    <p>I know there is a lot of similar questions are tons of great answers to this. I tried to look at the classical inheritance methods, or those closure methods etc. Somehow I consider they are more or less "hack" methods to me, as it doesn't really what the javascript is designed to do. (Welcome anybody correct me if I am wrong). OK, as long as it works, I satisfy with the classical inheritance pattern like:</p> <pre><code>PARENTClass = function (basevar) { do something here; }; PARENTClass.prototype = { a: b, c: d}; // prototype is auto gen // Inheritance goes here CHILDClass = function (childvar) { do something; }; CHILDClass.prototype = new PARENTClass(*1); // Actual inheritance to the prototype statement // Instance CHILDInstance = new CHILDClass(whatever); </code></pre> <p>Above is somehow, to my understanding the inheritance of JS. But one scenario I have no idea how to implement, is that what if I want to do some initializing DURING object creation (ie, within constructor), and the new object can be used right away.... My illustration on problem might not be too clear, so let me use the following C# Psuedo to explain what I want to do:</p> <pre><code>class PARENT { public PARENT (basevar) { ... } } class CHILD : PARENT { public CHILD (basevar) : PARENT (basevar) // constructor of child, and call parent constructor during construct. { ... } } </code></pre> <p>For some reason (like init. UI elements), putting them in constructor seems the best way to do. Anyone have idea on how can I do it.</p> <p>PS: in the *1, I have no idea what I should put there. PS2: The above situation I DID found the jquery.inherit library can do, I just wonder if not using library can achieve it. PS3: Or my understanding is wrong. Since javascript is not intended to mimick OOP (that's why i call it hack), what is the "CORRECT" logic to implement this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload