G-L > instanceof |
instanceof
지원 버전
Flash Player 6
구문
object instanceof class
매개 변수
object ActionScript 객체입니다.
class String이나 Date 같은 ActionScript 생성자 함수에 대한 참조입니다.
반환값
object가 class, instanceof의 인스턴스이면 true를 반환하고 그렇지 않으면 instanceof가 false를 반환합니다.
설명
연산자; 객체가 지정된 클래스에 속하는지 여부를 결정합니다. 또한 object가 class의 인스턴스인지 테스트합니다.
생성자 함수의 프로토타입 객체가 ActionScript 객체의 프로토타입 체인에 있으면 ActionScript 객체가 클래스의 인스턴스가 됩니다.
instanceof 연산자는 원시 유형을 래퍼 객체로 변환하지 않습니다. 예를 들어, 다음 코드는 true를 반환합니다.
new String("Hello") instanceof String
반면 다음 코드는 false를 반환합니다.
"Hello" instanceof String
예제
다음은 instanceof 연산자가 ActionScript 함수로 코드화될 때 어떤 모습을 하는지 보여줌으로써 instanceof 연산자의 알고리즘을 설명하는 예제입니다.
function instanceof (theObject, theClass){
while ((theObject = theObject.__proto__) != null) {
if (theObject == theClass.prototype) {
return true;
}
}
return false;
}
참고 항목