javascript - Some questions about object property descriptors and prototypes in JS
三叔
三叔 2017-07-05 10:37:23
0
4
857

Define an object and get the descriptor of a certain attribute: for example

let obj = {name: 'Andy'};
let descriptor = Object.getOwnPropertyDescriptor(obj, 'name');

The Object here should be a constructor. Why can the getOwnPropertyDescriptor method be called? Hope you can enlighten me

三叔
三叔

reply all(4)
世界只因有你

getOwnPropertyDescriptor is a static method

给我你的怀抱

Object is the top-level object of JavaScipr!

In js, there are two concepts: prototype and prototype chain. Instance objects only have prototype chains, while function objects and objects have their own prototypes.
Function objects and objects are the two top-level objects of JavaScipr, whether they are functions Whether instantiated objects, custom objects, array objects, etc., their prototypes are based on these two.

世界只因有你

This object is an object

学习ing
function Template () {
    // 在用 new 操作符 调用的时候,这就是构造函数
};

Template.staticMethod = function() {
    // 静态方法
};
Template.prototype.instanceMethod = function() {
    // 实例方法
};

This should not be difficult to understand
ObjectThe implementation principle is the same

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!