Created
November 9, 2011 22:57
-
-
Save goatslacker/1353443 to your computer and use it in GitHub Desktop.
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
Object.defineProperty(Object.prototype, "clone", { | |
value: function (proto) { | |
this.prototype = Object.create(proto.prototype, { | |
_super: { | |
value: proto.prototype | |
} | |
}); | |
}, | |
configurable: false, | |
enumerable: false, | |
writable: false | |
}); | |
var Person = function (name) { | |
this.name = name; | |
}; | |
Person.prototype.speak = function () { | |
return "Hello! I'm " + this.name; | |
}; | |
var SWEngineer = function (name) { | |
Person.call(this, name); | |
}; | |
SWEngineer.clone(Person); | |
SWEngineer.prototype.speak = function () { | |
return this._super.speak.call(this) + " and I program."; | |
}; | |
var josh = new SWEngineer("Josh"); | |
console.log(josh.speak()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment