Created
May 28, 2013 20:05
-
-
Save dcherman/5665673 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
| if ( !Object.create ) { | |
| Object.create = function( parentProto ) { | |
| function F() {} | |
| F.prototype = parentProto; | |
| return new F(); | |
| } | |
| } | |
| function Animal() {} | |
| Animal.prototype.speak = function() { | |
| throw new Error( "Not implemented" ); | |
| }; | |
| Animal.extend = function( proto ) { | |
| var i; | |
| function Child() {} | |
| Child.prototype = Object.create( this.prototype ); | |
| for( i in proto ) { | |
| Child.prototype[ i ] = proto[ i ]; | |
| } | |
| Child.extend = this.extend; | |
| return Child; | |
| } | |
| var Dog = Animal.extend({ | |
| speak: function() { | |
| console.log( "WOOF" ); | |
| } | |
| }); | |
| var dog = new Dog(); | |
| dog.speak(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment