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 obj = {}; | |
console.log(obj.toString()) // [object 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
function Rabbit(name) { | |
this.name = name; | |
} | |
Rabbit.prototype.sayHi = function() { | |
console.log( this.name ); | |
} | |
var rabbit = new Rabbit('Rabbit'); | |
rabbit.sayHi(); // (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
function Rabbit(name) {} | |
Rabbit.prototype = { | |
eats: true | |
}; | |
var rabbit = new Rabbit(); | |
delete Rabbit.prototype.eats; // (*) | |
console.log( rabbit.eats ); // (5) ? |
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
function Rabbit(name) {} | |
Rabbit.prototype = { | |
eats: true | |
}; | |
var rabbit = new Rabbit(); | |
delete rabbit.eats; // (*) | |
console.log( rabbit.eats ); // (4) ? |
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
function Rabbit(name) {} | |
Rabbit.prototype = { | |
eats: true | |
}; | |
var rabbit = new Rabbit(); | |
Rabbit.prototype.eats = false; // (*) | |
console.log( rabbit.eats ); // (3) ? |
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
function Rabbit() {} | |
Rabbit.prototype = { | |
eats: true | |
}; | |
var rabbit = new Rabbit(); | |
Rabbit.prototype = {}; // (*) | |
console.log( rabbit.eats ); // (2) ? |
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
function Rabbit(name) {} | |
Rabbit.prototype = { | |
eats: true | |
}; | |
var rabbit = new Rabbit(); | |
Rabbit.prototype.eats = false; | |
console.log( rabbit.eats ); |
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
function Rabbit() {} | |
Rabbit.prototype = { | |
eats: true | |
}; | |
var rabbit = new Rabbit(); | |
console.log(rabbit.eats ); // (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 = { | |
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 |
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 | |
}; |