1
2
3
4
5
6
7
function Guitar(){}
console.log(Guitar.prototype); // Prototype Object
/*
constructor: ƒ Guitar()
__proto__: Object
*/
1
2
3
4
function Guitar(){}
const electric = new Guitar();
console.log(electric.constructor === Guitar) // true
1
2
3
4
function Guitar(){}
const electric = new Guitar();
console.log(electric.__proto__ === Guitar.prototype) // true
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function Guitar(){
this.head = true;
this.string = 6;
}
Guitar.prototype.playing = function(){
return '딩가 딩가';
}
var electric = new Guitar();
console.log(electric.playing()) // "딩가 딩가"
/*
electric.__proto__ === Guitar.prototype
Guitar.prototype 을 검색하여 playing() 을 가져옴
*/
1
2
3
4
5
6
7
8
9
10
11
function Guitar(){}
Guitar.prototype.head = true;
Guitar.prototype.string = 6;
var electric = new Guitar();
console.log(electric.prototype === Guitar()) // true
console.log(electric.constructor === Guitar) // true
console.log(electric.__proto__ === Guitar.prototype) // true
console.log(electric.string === Guitar.prototype.string) // true
출처 : https://medium.com/@bluesh55/javascript-prototype-%EC%9D%B4%ED%95%B4%ED%95%98%EA%B8%B0-f8e67c286b67
https://medium.com/@bluesh55/javascript-prototype-%EC%9D%B4%ED%95%B4%ED%95%98%EA%B8%B0-f8e67c286b67