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 animal = { | |
| eats: true | |
| }; | |
| var rabbit = { | |
| jumps: true, | |
| __proto__: animal | |
| }; | |
| for (var key in rabbit) { |
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 animal = { | |
| eats: true | |
| }; | |
| var rabbit = { | |
| jumps: true, | |
| __proto__: animal | |
| }; | |
| for (var key in rabbit) { |
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 rabbit = {foo: 'bar'}; | |
| rabbit.__proto__ = window; | |
| console.log(rabbit.location) // call location object through window object |
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
| let owl = { | |
| sayHello(str) { | |
| return `Hello ${str} !`; | |
| } | |
| } | |
| let winnie = {}; | |
| winnie.__proto__ = owl; | |
| let donkey = {}; |
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
| let animal = {}, | |
| rabbit = {}; | |
| Object.setPrototypeOf(rabbit, animal); // rabbit.__proto__ = animal | |
| console.log(Object.getPrototypeOf(rabbit) === animal ) // true |
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 animal = {eats: true}; | |
| var rabbit = Object.create(animal); //rabbit.__proto__ = animal | |
| console.log(rabbit.eats) //true |
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 data = Object.create(null); | |
| data.text = "Hello!"; | |
| console.log(data.text); // Hello! | |
| console.log(data.toString); // undefined | |
| console.log(data.__proto__); |
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
| let animal = { | |
| jumps: null | |
| }; | |
| let rabbit = { | |
| jumps: true | |
| }; | |
| rabbit.__proto__ = animal; | |
| console.log( rabbit.jumps ); // ? (1) |
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 animal = { | |
| eat: function() { | |
| this.full = true; | |
| } | |
| }; | |
| var rabbit = { | |
| __proto__: animal | |
| }; |
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 animal = { | |
| eats: true | |
| }; | |
| function Rabbit(name) { | |
| this.name = name; | |
| //this.__proto__ = animal; won't work in IE10+ | |
| } | |
| Rabbit.prototype = animal; //only object, primitives won't work |