Skip to content

Instantly share code, notes, and snippets.

@lamp
Created August 9, 2010 14:42
Show Gist options
  • Save lamp/515496 to your computer and use it in GitHub Desktop.
Save lamp/515496 to your computer and use it in GitHub Desktop.
Parent = function(){};
Parent.prototype = {
parentMethod : function(){ alert('Parent') }
};
Child = function(){}
Child.prototype.__proto__ = Parent.prototype;
Child.prototype.__super = Parent
c = new Child();
c.parentMethod() //alerts parent
@lamp
Copy link
Author

lamp commented Aug 9, 2010

This:
Child.prototype.proto = Parent.prototype;

is analagous to:

for(i in Parent.prototype){
Child[i] = Parent[i];
}

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