Skip to content

Instantly share code, notes, and snippets.

@glenjamin
Created May 29, 2011 12:19
Show Gist options
  • Save glenjamin/997739 to your computer and use it in GitHub Desktop.
Save glenjamin/997739 to your computer and use it in GitHub Desktop.
Taking advantage of javascript function hoisting for more readable class definitions
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