Properties and methods of JavaScript prototype objects

Source: Internet
Author: User

The prototype chain structure of ordinary objects is described earlier, the properties and methods in the prototype object are introduced, then the prototype chain of the function object is introduced, and the prototype chain is finally integrated.

The properties and methods of the first part Object.prototype

1 Object.prototype.toString method

Because the ToString method is defined in the Object.prototype top-level object, any object has a ToString method.

can be used to detect the type of object, of course, can only detect the type of built-in objects, if it is a custom constructor created by the object can not accurately detect the type.

How to use: Object.prototype.toString.call (object)

Output: "[object constructor name]"

The second value in the result of the final output is the object type that corresponds to the object.

2 Object.prototype.hasOwnProperty ()

Determines whether a property belongs to the object itself, not the inherited property, and the return value is true or false.

All objects can call this method directly.

3 Object.prototype.isPrototypeOf ()

Determines whether the current object is a prototype object of a Parameter object, and returns a value of TRUE or false.

All objects can call this method directly.

4 Object.prototype.propertyIsEnumerable ()

Detects whether this property can be enumerated in an object, returns a value of TRUE or false.

Whether it can be enumerated refers to the ability to access this property through the for...in Loop statement.

The prototype chain of the second part of the function object

The prototype chain of a function object is also based on the object prototype chain.

We can conclude two conclusions:

A any function is an instance of the function constructor (including constructors, such as object, and function itself, which means that you have created yourself): function. __proto__===function.prototype===function.__ proto__

The prototype object of B Function inherits from the prototype object of object: Function.prototype.__proto__===object.prototype

Finally we conclude that Object.prototype is the top-level object for all objects.

The third part of the integration of prototype chain

The concept of prototype chain is abstract, I have drawn a prototype structure here, can be convenient to remember, of course, you can directly use the browser's developer tools to find the prototype chain structure of an object.

Properties and methods of JavaScript prototype objects

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.