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
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(); | |
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 ); // (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(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(); | |
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) { | |
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
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
var arr = [1, 2, 3]; | |
console.log(arr) // 1,2,3, result of arr.__proto__ -> Array.prototype.toString |
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
/* | |
1. create method in string prototype | |
2. it should return multiple repeated string by n times | |
consle.log( "foo".repeat(3) ); // 'foofoofoo' | |
*/ | |
String.prototype.repeat = function(times) { //or use built-in ES6 repeat() | |
return new Array(times + 1).join(this); | |
}; |