Last active
August 29, 2015 14:02
-
-
Save tanem/498b6f8f7266fd59f0f0 to your computer and use it in GitHub Desktop.
object linking with Object.create()
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 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