Skip to content

Instantly share code, notes, and snippets.

@ovaillancourt
Created September 13, 2013 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ovaillancourt/6553150 to your computer and use it in GitHub Desktop.
Save ovaillancourt/6553150 to your computer and use it in GitHub Desktop.
function Parent(){
this.value = 'Parent';
}
Parent.staticMethod = function(){
console.log( 'staticMethod called on Parent' );
}
function Child(){
Parent.call(this);
}
// Child.prototype = Object.create(Parent.prototype);
// Child.prototype.constructor = Child; //<- Important to set the constructor here.
//2 commented lines above are equivalent to the following:
require('util').inherits(Child, Parent);
Child.staticMethod = function(){
console.log( 'staticMethod called on child' );
};
var parent = new Parent();
var child = new Child();
parent.constructor.staticMethod();
child.constructor.staticMethod();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment