0
instanceof
메서드를 검사 할 때 결과가 동일하지 않습니다.javascript 프로토 타입 생성자 및 instanceof
function A(){}
function B(){};
먼저 I 위 복귀 true
에 A
A.prototype = B.prototype;
var carA = new A();
console.log(B.prototype.constructor);
console.log(A.prototype.constructor == B);
console.log(B.prototype.constructor == B);
console.log(carA instanceof A);
console.log(carA instanceof B);
마지막 4 상태로, prototype
(참조) 속성을 지정.
하지만 B의 constructor
을 할당하려고했을 때 결과가 같지 않습니다. false
을 반환 carA instanceof B
이 경우에
A.prototype.constructor = B.prototype.constructor;
var carA = new A();
console.log(B.prototype.constructor);
console.log(A.prototype.constructor == B);
console.log(B.prototype.constructor == B);
console.log(carA instanceof A);
console.log(carA instanceof B);
. 이