Flash Player 6.
object
instanceof
class
object
An ActionScript object.
class
A reference to an ActionScript constructor function, such as String or Date.
If object
is an instance of class
, instanceof
returns true
; otherwise, instanceof
returns false
.
Operator; determines whether an object belongs to a specified class. Tests if object
is an instance of class
.
An ActionScript object is said to be an instance of a class if the constructor function's prototype object is in the ActionScript object's prototype chain.
The instanceof
operator does not convert primitive types to wrapper objects. For example, the following code returns true
:
new String("Hello") instanceof String
Whereas the following code returns false
:
"Hello" instanceof String
To illustrate the algorithm of the instanceof
operator, the following example shows how the instanceof
operator might look if it was coded as an ActionScript function.
function instanceof (theObject, theClass){ while ((theObject = theObject.__proto__) != null) { if (theObject == theClass.prototype) { return true; } } return false; }