Apr 172007
is와 instanceof 연산자는 주어진 객체가 특정한 데이터 타입인지를 판별하기 위해 사용됩니다.
is 연산자는 어떤 오브젝트가 특정한 데이터 타입, 클래스 또는 인터페이스와 일치하는지 판별합니다.
반면, instanceof 연산자는 어떤 표현식의 프로토타입 체인이 특정한 함수의 프로토타입 오브젝트를 포함하는지 판별합니다. (쓰면서도 뭔 말인지 잘 이해는 안됨 ㅠㅠ)
어쨌든 어떤 객체가 어떤 클래스에 속하는지 아닌지를 알고자 할 때 사용할 수 있습니다.
그러나 instanceof는 인터페이스를 인식하지 못하기 때문에 is를 사용하는 것이 더 좋을것 같네요.
게다가 컴파일 시에도 instanceof대신 is를 사용하라고 태클을 걸어오고요.
1 2 3 4 5 6 7 8 9 10 11 12 | import flash.display.*; import flash.events.IEventDispatcher; var mySprite:Sprite = new Sprite(); trace(mySprite is Sprite); // true trace(mySprite is DisplayObject); // true trace(mySprite is IEventDispatcher); // true trace(mySprite instanceof Sprite); // true trace(mySprite instanceof DisplayObject); // true trace(mySprite instanceof IEventDispatcher); // false |
Recent Comments