다음과 같은 코드가 있다고 가정 해 보겠습니다.Object Literal의 프로토 타입 설정
var A = {a:10};
var B = {b:20};
B.prototype = A;
alert(B.a);
B.a에 대해 정의되지 않았습니다. 내가 잘못하고 있니? 객체 리터럴의 프로토 타입을 어떻게 설정합니까?
저는 Constructor 객체에서하는 방법을 알고 있습니다. 따라서 다음 코드는 완벽합니다.
function A(){this.a=10}
function B(){this.b=20}
B.prototype = new A();
b = new B;
alert(b.a);
개체 리터럴에서는 어떻게합니까?
관련 : http://stackoverflow.com/q/ 7015693/989121 – georg
짧은 대답 : 당신은 할 수 없습니다 – slebetman
가능한 duplicat http://stackoverflow.com/questions/9959727/java-script-what-is-the-difference-between-proto-and-prototype 또는 http://stackoverflow.com/questions/572897/how-does- javascript-prototype-work? lq = 1 또는 http://stackoverflow.com/questions/650764/how-does-proto-differ-from-constructor-prototype?rq=1 또는 http://stackoverflow.com/questions/ 9451881/prototype-vs-prototype-what-is-the-difference-mycons-proto-myco/9451979 # 9451979 –