0
여기에는 개체 인수를 사용하고 전달 된 개체를 사용하여 새로 만든 개체를 프로토 타입 개체로 반환하는 간단한 상속 함수가 있습니다. 내 inherit
기능을 실행 한 후프로토 타입 객체의 속성을 표시 하시겠습니까?
function inherit(p) {
if (p == null) throw TypeError(); //p must not be null
if(Object.create) { //if the object.create method is defined
return Object.create(p); //use it
}
//type checking
var typeIs = typeof p; //variable that holds type of the object passed
if(typeIs !== 'object' && typeIs !== 'function') {
throw TypeError();
}
function f() {}; //dummy constructor
f.prototype = p; //prototype
return new f(); //return new constructor
}
var $f0 = {};
$f0.x = 1;
var $g0 = inherit($f0);
$g0.y = 2;
var $h0 = inherit($g0);
console.log('x' in $h0); //true
console.log(Object.getOwnPropertyNames($h0.prototype)); //throws error
문제 나는 데 나는 객체의 프로토 타입 특성을 찾아 볼 수없는 생각이다.
프로토 타입 개체 속성을 표시하려면 어떻게해야합니까?
'$ h0 .__ proto__','.prototype'은 생성자 함수의 속성이 아닙니다. 객체는 – Esailija
입니다. 이것이 이것을 성취하는 유일한 방법입니까? 나는'__proto__'가 표준이 아니었다는 인상을 받았다. – Sethen