API Docs for: 0.3.0
Show:

Utils.inherit Class

Module: Utils

Provide an useful way to use inheritance.

Note: inherit is not a class but a standalone function.

Internally, inherit use a intermediate dummy function as prototype. So, inherit doesn't call the parent constructor, unlike to the classic inheritance method.

// class Parent
function Parent(arg) {
     do_some_stuff(arg);
}

Parent.prototype.foo = "Hello";

//class Child
function Child(arg, arg2) {
     //Parent constructor call.
     Parent.call(this, arg);

     do_other_stuff(arg2);
}

inherit(Child, Parent);

var child = new Child(1, 2);

console.log(child instanceof Parent);    //true
console.log(child.foo);                  //"Hello"

Warning: this function rewrite the prototype of child. All change must be done after the call to inherit, otherwise they will be erased.

Constructor

Utils.inherit

(
  • child
  • parent
)

Parameters:

  • child Object

    Child class

  • parent Object

    Parent class

Item Index