JavaScript learns an Object

Source: Internet
Author: User
Tags hasownproperty

constructor function
New Object () New object (value)
Parameters
Value
An optional parameter that declares the original value (that is, a number, a Boolean, or a string) to be converted to a numeric object, a Boolean object, or a string object. Versions prior to JavaScript 1.1 and ECMAScript VL do not support this object.

return value

If the value parameter is not passed to the constructor, it returns a newly created instance of object. If the original value parameter is specified, the constructor creates and returns a wrapper object, the Number object, a Boolean object, or a string object. When you call the object () constructor as a function without using the new operator, it behaves as if you were using the new operator.

Property
Constructor

A reference to a JavaScript function that is the constructor of the object

Method 1.hAsownproperty ()

Checks whether an object has a locally defined (non-inherited) property with a specific name.

<script type= "Text/javascript" >
var o = new Object ();
O.name= "Tom";
Alert (O.hasownproperty ("name")); True
Alert (O.hasownproperty ("Age")); False
</script>

2.isPrototypeOf ()

Grammar
object. isprototypeof (o)

Parameters
o

Any object.

return value

Returns true if object is a prototype of O. Returns False if O is not an object, or if object is not a prototype of O.

Describe

JavaScript objects inherit the properties of the prototype object. The prototype of an object is referenced by the prototype property of the constructor that is used to create and initialize the object. The isPrototypeOf () method provides a way to determine whether an object is a prototype of another object. This method can be used to determine the class of an object.

Example
var o = new Object (  );                          Create an Object Object.prototype.isPrototypeOf (o)                //True:o is an object Function.prototype.isPrototypeOf (o.tostring);    True:tostring is a function of Array.prototype.isPrototypeOf ([+]);          True: [All-in-one] is an array//the following is another way to perform the same test (O.constructor = = Object);  True:o is created with Object (  ) constructor (O.tostring.constructor = = Function);  True:o.tostring is a function/prototype is the object itself to the prototype object. The following call returns the true//description function following the Function.prototype and Object.prototyp properties. Object.prototype.isPrototypeOf (Function.prototype);

3.ProertyIsEnumerable ()
Grammar
object. propertyisenumerable (propname)
Parameters
propname

A string that contains the name of the object prototype.

return value

Returns true if object has a non-inherited property named PropName, and the property is enumerable (that is, it can be enumerated with the for/in Loop).

Describe

Use the For/in statement to iterate through an object's "enumerable" properties. But not all of the properties of an object are enumerable, and the properties that are added to the object through JavaScript code are enumerable, and the predefined properties of the inner object, such as methods, are usually non-enumerable. The Propertylsenumerable () method provides a way to differentiate between enumerable and non-enumerable properties. Note, however, that the ECMAScript standard stipulates that the propertyIsEnumerable () method does not detect the prototype chain, which means that it applies only to the local properties of the object and cannot detect the enumerable of inherited properties.

Example
var o = new Object (  );                Create an object o.x = 3.14;                            Define-a property o.propertyisenumerable ("X");           True Property x is a local, enumerable o.propertyisenumerable ("Y");           False:o has no attribute yo.propertyisenumerable ("toString");    The FALSE:TOSTRLNG attribute is an inherited Object.prototype.propertyIsEnumerable ("toString");  False: Enumeration of the
Bug

When the standard limit propertylsenumerable () method can only detect non-inherited attributes, it is obviously wrong. Internet Explorer 5.5 implements this method by standard. The NESTACPE 6.0 implementation of the propertyIsEnumerable () method takes into account the prototype chain. While this method is preferable, it conflicts with the standard, so Netscape 6.1 modifies it so that it matches IE 5.5. Because of this error in the standard, this method is not so useful.

JavaScript learns an Object

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.