Created
June 18, 2018 00:14
-
-
Save sevperez/df39004928e5142b8138df7d6bdfe7d3 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
| var Robot = { | |
| init: function(name, job) { | |
| this.name = name; | |
| this.job = job; | |
| }, | |
| introduce: function() { | |
| console.log("Hi! I'm " + this.name + ". My job is " + this.job + "."); | |
| }, | |
| }; | |
| var bender = Object.create(Robot); | |
| bender.init("Bender", "bending"); | |
| bender.introduce(); // Hi! I'm Bender. My job is bending. | |
| console.log(Object.getPrototypeOf(bender) === Robot); // true | |
| var wallE = Object.create(Robot); | |
| wallE.init("Wall-E", "trash collection"); | |
| wallE.introduce(); // Hi! I'm Wall-E. My job is trash collection. | |
| console.log(Object.getPrototypeOf(wallE) === Robot); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment