1
왜 경고 (John.hasOwnProperty ('firstName')); firstName은 Person 프로토 타입에 정의 된 반면에 John은 정의하지 않는 반면 true를 반환합니다.자바 스크립트 hasOwnProperty는 false 대신 true를 반환합니까?
https://jsfiddle.net/xfdnsg2w/
Person = function(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
var John = new Person("John");
alert(John.hasOwnProperty('toString'));
alert(John.hasOwnProperty('firstName'));
'Person.prototype'에 정의했다면'Person.prototype.firstName'에 할당 할 수 있습니다. 'firstName'과'lastName'과 같은 속성은 일반적으로 사용자가 정의한 방식으로 정의되며 인스턴스에 따라 다릅니다 (프로토 타입 체인이 아닌 객체 자체가 소유합니다). –