Skip to content

Instantly share code, notes, and snippets.

@juandopazo
Created August 9, 2012 16:23
Show Gist options
  • Save juandopazo/3305606 to your computer and use it in GitHub Desktop.
Save juandopazo/3305606 to your computer and use it in GitHub Desktop.
Inheriting constructor properties with __proto__
function Superclass() {
}
Superclass.prototype.someMethod = function () {
console.log('foo');
};
Superclass.staticMethod = function () {
console.log('I\'m "static"');
};
function Subclass() {
}
Subclass.__proto__ = Superclass; // this makes Subclass.staticMethod() work
Subclass.prototype = Object.create(Superclass.prototype); // this makes (new Subclass()).someMethod() work
@demian85
Copy link

demian85 commented Aug 9, 2012

@juandopazo
Copy link
Author

Interesante. Igual todo parece indicar que van a estandarizar __proto__ como "opcional" o algo así.

@ialcazar
Copy link

But proto is a non-standard way of accessing the internal prototype...I feel confused because you prefer proto instead of classic prototype :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment