Skip to content

Instantly share code, notes, and snippets.

@fetchTe
Created November 5, 2015 22:22
Show Gist options
  • Save fetchTe/c9712375860a10c612a1 to your computer and use it in GitHub Desktop.
Save fetchTe/c9712375860a10c612a1 to your computer and use it in GitHub Desktop.
//oo
function Foo(who) {
this.me = who;
}
Foo.prototype.identify = function () {
return this.me;
}
function Bar (who) {
Foo.call(this, who);
}
Bar.prototype = Object.create( Foo.prototype );
Bar.prototype.speak = function () {
console.log('Hello my name is, ' this.identify());
}
var b1 = new Bar('b1');
var b2 = new Bar('b2');
b1.speak();
b2.speak();
//oloo
Foo = {
init: function (who) {
this.who = who;
},
identify: function () {
return this.me;
}
}
Bar = Object.create( Foo );
Bar.speak = function () {
console.log('Hello my name is, ' this.identify());
}
var b1 = Object.create( Bar );
b1.init('b1');
var b2 = Object.create( Bar );
b2.init('b2');
b1.speak();
b2.speak();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment