Created
September 13, 2013 16:48
-
-
Save ovaillancourt/6553150 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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