Created
May 29, 2011 12:19
-
-
Save glenjamin/997739 to your computer and use it in GitHub Desktop.
Taking advantage of javascript function hoisting for more readable class definitions
This file contains hidden or 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
var util = require('util'); | |
function Parent(){} | |
// Note we declare inheritance and static properties *before* the constructor | |
util.inherits(Child, Parent); | |
Child.static_property = 1; | |
function Child(){}; | |
var c = new Child(); | |
console.log(c instanceof Child); // => true | |
console.log(c.constructor.static_property); // => 1 | |
console.log(c instanceof Parent); // => true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment