귀중하게 받아 들여진 대답을 신뢰하는 것은 실제로 저를 조금 문제로 만들었습니다. 프로토 타입 관련 차이점 이상으로 진행되는 것으로 보입니다. 내가 찾은 것은
hasOwnProperty는 해당 키가 참조 유형이지만 in 연산자는 사전에 키가 있는지 확인할 수 없습니다.
다음은 예제입니다.
코드 :
var test:Function = function(key:*,label:String):void
{
var d:Dictionary = new Dictionary(true);
d[key] = true;
trace(label);
trace(" hasOwnProperty: " + (d.hasOwnProperty(key)?"true":"false <== !!PROBLEM!!"));
trace(" in: " + (key in d));
trace(" []: " + d[key]);
};
test({}, "indexed by object");
test("string", "key is string");
test(0, "key is number");
test(true, "key is boolean");
결과 :
indexed by object
hasOwnProperty: false <== !!PROBLEM!!
in: true
[]: true
key is string
hasOwnProperty: true
in: true
[]: true
key is number
hasOwnProperty: true
in: true
[]: true
key is boolean
hasOwnProperty: true
in: true
[]: true
그리고 아직도 그것에 더있어. hasOwnProperty는 정적 검색을 지원하지 않습니다. 예를 들어,'** 정적 속성 **'- 객체의 정의 클래스 나 그 수퍼 클래스의 static 키워드로 정의 된 변수, 상수 또는 메소드; '** Prototype properties **'- 객체의 프로토 타입 체인의 일부인 프로토 타입 객체에 정의 된 속성. '거짓 '을 반환합니다. –
정적 또는 프로토 타입 속성 또는 메서드가 있는지 확인하지 않기 때문에 'hasOwnProperty'가 아닌 속성이나 메서드에 액세스하면 오류가 발생하는지'in'을 보면 알 수 있습니다. –