Original Author: fictiony
From: Blue Ideal
Write a set of models of their own time by the way to arrange out, posted out for everyone to see, hope to be helpful to everyone.
Properties: Object.constructor
This property is defined in the prototype of the class, which can be invoked by an object instance after the object instance is created and points to the constructor of the current class. This allows you to determine which class the object directly belongs to (unlike instanceof, instanceof is not limited to the class that the object directly belongs to, even if the parent class returns True).
Example
Trace (Object.prototype.constructor = = Object); Output true
var a = new Object ();
Trace (A.constructor = = Object); Output true
var B = new Array ();
Trace (B.constructor = = Array); Output true
Trace (B.constructor = = Object); Output false
Trace (b instanceof Object); Output true
Properties: object.__constructor__
This property function is similar to Object.constructor, except that it is not defined in the prototype of the class, but rather when the object instance is created and appended to the object instance. Also, this property is implicitly invoked when the Super keyword is used as the parent class constructor to point to the constructor of the parent class, that is, super (...). Equivalent to This.__constructor__.call (this, ...).
Example
Trace (object.prototype.__constructor__ = = Object); Output false
var a = new Object ();
Trace (a.__constructor__ = = Object); Output true
var B = new Array ();
Trace (b.__constructor__ = = Array); Output true
Trace (b.__constructor__ = = Object); Output false
Method: Object.isprototypeof (Classfunc)
This method is used to determine whether the current object is in the __proto__ chain of object obj. This method can be used to determine whether a class is a parent class or subclass of another class.
Example
Trace (Object.prototype.isPrototypeOf (New Object ()); Output true
Trace (Object.prototype.isPrototypeOf) (New Array ()); Output true
Trace (Array.prototype.isPrototypeOf (New Object ()); Output false
Trace (Object.prototype.isPrototypeOf (array.prototype)); Determines whether object is a parent of array, and outputs true
Method: Object.ispropertyenumerable (propname)
This method is used to determine whether a member named PropName exists in the current object and can be enumerated (using for ...). In, in other words, is visible (use the Assetpropflags global function to set whether the object property is visible).
Example
var a = {x:1, y:2};
Assetpropflags (A, ["Y"], 1); Set Y to Invisible
Trace (A.Y); can still output 2
for (var i in a) trace (i); Output x only
Trace (A.ispropertyenumerable ("X")); Output true
Trace (a.ispropertyenumerable ("Y")); Output false
Method: Object.hasownproperty (propname)
This method is used to determine whether a member named PropName is a member of the current object, rather than being referenced by the __proto__ chain from the prototype of the class.
Example
function Test () {}
test.prototype.x = 1;
var a = new test ();
A.Y = 2;
Trace (a.x); Output 1
Trace (A.hasownproperty ("X")); Output false
Trace (A.Y); Output 2
Trace (A.hasownproperty ("Y")); Output true
Method: Object.ToString ()
This method defines the string result that an object produces when converting to a string type, which is generally defined in the prototype of the class.
Example
function point (x, y) {
this.x = x;
This.y = y;
}
point.prototype.toString = function () {
Return "[x:" + this.x + ", y:" + this.y +] ";
};
var pos = new Point (10, 20);
Trace ("position is " + pos); //output  POSITION IS [X:10, Y:20]
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.