Skip to content

Instantly share code, notes, and snippets.

@jakearchibald
Created January 9, 2010 00:10
Show Gist options
  • Save jakearchibald/272602 to your computer and use it in GitHub Desktop.
Save jakearchibald/272602 to your computer and use it in GitHub Desktop.
function MyConstructor() {
var instance = function() {
alert('yey');
}
instance.constructor = MyConstructor;
instance.__proto__ = MyConstructor.prototype;
return instance;
}
MyConstructor.prototype.instanceMethod = function() {
alert('woo');
}
var myInstance = new MyConstructor;
alert(myInstance instanceof MyConstructor); // true
myInstance.instanceMethod(); // woo
myInstance(); // yey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment