Last active
September 8, 2016 01:44
-
-
Save danilodeveloper/c62303ff50bd6059dbfd to your computer and use it in GitHub Desktop.
This file contains 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
var Foo = { | |
init: function(who) { | |
this.me = who; | |
}, | |
identify: function() { | |
return "I am " + this.me; | |
} | |
}; | |
Foo.create = function() { | |
return Object.create(this); | |
} | |
var Bar = Foo.create(); | |
Bar.speak = function() { | |
alert("Hello, " + this.identify() + "."); | |
}; | |
Bar.create = function(param) { | |
var a = Object.create(this); | |
a.init(param); | |
return a; | |
} | |
var b1 = Bar.create('b1'); | |
var b2 = Bar.create('b2'); | |
b1.speak(); // alerts: "Hello, I am b1." | |
b2.speak(); // alerts: "Hello, I am b2." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment