The constructor Property

687 ワード

[size=medium]Since constructor functions define new categories or clases of object、the constructor property can help
determine the type of an object.For example,you might use code like the follwing to determine the type
of an unknown value:
if ((typeof o == "object") && (o.constructor == Date))
     // Then do something with the Date object...
The instance of operator checks the value of the constructor property、so the code above could also be
written:
if ((typeof o == "object") && (o instanceof Date))
     // Then do something with the Date object...
[/size]