Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Why you dont use standard javascript function inheritance? For example:</p> <pre><code>function inherit(childClass,parentClass) { var f=function(){}; // defining temp empty function f.prototype=parentClass.prototype; f.prototype.constructor=f; childClass.prototype=new f; childClass.prototype.constructor=childClass; // restoring proper constructor for child class parentClass.prototype.constructor=parentClass; // restoring proper constructor for parent class } Employee = function Employee(/*list of constructor parameters, if needed*/) { } Employee.prototype.paygrade = 1; Employee.prototype.name = ""; Employee.prototype.dept = "general"; Employee.prototype.salary = function() { return this.paygrade * 30000; } WorkerBee = function WorkerBee(/*list of constructor parameters, if needed*/) { this.projects = ["Project1", "Project2"]; } inherit(WorkerBee,Employee); // for this implementation of *inherit* must be placed just after defining constructor WorkerBee.prototype.paygrade = 2; WorkerBee.prototype.projects = null; // only literals and function-methods can properly initialized for instances with prototype Engineer = function Engineer(/*list of constructor parameters, if needed*/) { } inherit(Engineer,WorkerBee); Engineer.prototype.dept = "Programming"; Engineer.prototype.language = "Objective-C"; var jane = new Engineer(/*Engineer parameters if needed*/); var jill = new Engineer(/*Engineer parameters if needed*/); var cow = new Employee(/*Employee parameters if needed*/); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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