2012-08-04 8 views
2

내가 지금과 같은 새로운 개체를 만들 수 object.create 사용Object.create 및 프로토 타입

o = {x:1,y:2}; 
p = Object.create(o); 

나는 O를 P의 프로토 타입이되고 모든 메소드를 상속하는 인상입니다.

은 그럼 왜, 내가

print(p.prototype); 

때 출력은 정의되지 않습니다? o는 잘 정의되어 있습니다!

op의 프로토 타입이 op의 생성자의 프로토 타입을 의미하게, 당신은

답변

2

이 시도 감사드립니다.

console.log(p.constructor.prototype); 

var o = {x:1,y:2}; 
var p = Object.create(o); 

당신은 할 수 이미지로 위, 아래 :

var o = {x:1,y:2}; 
function constructor_of_p(){}; 
constructor_of_p.prototype = o; 
var p = new constructor_of_p();