Home > Web Front-end > JS Tutorial > body text

What are the three properties of a javascript object?

php中世界最好的语言
Release: 2018-03-16 17:22:16
Original
2072 people have browsed it

This time I will bring you javascript objectwhat are the three attributes, what are the notesof the three attributes of javascript object, the following is a practical case, let's take a look.

Each object has a prototype, class, and extensible attribute associated with it.

Prototype property

The prototype property of an object is used to inherit properties.
The prototype property is set at the beginning of the creation of the instance object. The object created through the object directly uses Object.prototype as their prototype. Objects created through new use the prototype attribute of the constructor as their prototype. Objects created through Object.create() use the first parameter (which can also be null) as their prototype.

* 检测一个对象是否是另一个对象的原型(或处于原型链中),使用isPrototypeOf()方法  var p = { x: 1 };  var o = Object.create(p);
  p.isPrototypeOf(o); // true
  Object.prototype.isPrototypeOf(o);  // true
Copy after login

Class attribute

The class attribute of an object is a string that represents the type information of the object.
To get the class of the object, you can call the toString() method of the object, and then extract the string between the 8th and the penultimate position of the returned string. However, many objects inherit 's toString() method and override it. In order to call the correct toString() version, the Function.call() method must be called indirectly.
eg:

   function classof(o) {        if(o === null) return "Null";        if(o === undefined) return "Undefined";        return Object.prototype.toString.call(o).slice(8,-1);
    }
Copy after login

Extensibility

The extensibility of an object indicates whether new properties can be added to the object. All built-in objects and custom objects are explicitly extensible, as defined by the host object's extensibility roommate, the JavaScript engine. In ECMAScript 5, all built-in and custom objects are extensible unless they are converted to non-extensible. Likewise, the extensibility of host objects is defined by the JavaScript engine that implements ECMAScript 5.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Several ways of AngularJS dependency injection

Detailed explanation of $watch, $apply and $digest data binding processes

JavaScript code to create a dynamic menu or drop-down list

What are the built-in objects of js

The above is the detailed content of What are the three properties of a javascript object?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!