Skip to content

Instantly share code, notes, and snippets.

@tanem
Last active August 29, 2015 14:02
Show Gist options
  • Save tanem/498b6f8f7266fd59f0f0 to your computer and use it in GitHub Desktop.
Save tanem/498b6f8f7266fd59f0f0 to your computer and use it in GitHub Desktop.
object linking with Object.create()
var Animal = {
sayHello: function(){
console.log('Hello from ' + this.name);
}
};
var Cat = Object.create(Animal);
Cat.init = function(name){
this.name = name;
};
var fatty = Object.create(Cat);
fatty.init('Fatty');
var skinny = Object.create(Cat);
skinny.init('Skinny');
fatty.sayHello();
skinny.sayHello();
console.log(Cat.isPrototypeOf(fatty));
console.log(Cat.isPrototypeOf(skinny));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment