search

Home  >  Q&A  >  body text

javascript - Some questions about object property descriptors and prototypes in JS

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

三叔三叔2691 days ago888

reply all(4)I'll reply

  • 世界只因有你

    世界只因有你2017-07-05 10:39:23

    getOwnPropertyDescriptor is a static method

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-07-05 10:39:23

    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.

    reply
    0
  • 世界只因有你

    世界只因有你2017-07-05 10:39:23

    This object is an object

    reply
    0
  • 学习ing

    学习ing2017-07-05 10:39:23

    function Template () {
        // 在用 new 操作符 调用的时候,这就是构造函数
    };
    
    Template.staticMethod = function() {
        // 静态方法
    };
    Template.prototype.instanceMethod = function() {
        // 实例方法
    };

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

    reply
    0
  • Cancelreply