码迷,mamicode.com
首页 > Web开发 > 详细

js {}与class属性描述符的区别

时间:2020-12-25 11:52:31      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:prototype   hello   cto   table   区别   prope   fine   set   als   

let data = {
  name: "ajanuw",
  change() {
    this.name = "Ajanuw";
  },
  get message() {
    console.log(this);
    return "hello " + this.name;
  },
};
console.log( Object.getOwnPropertyDescriptors(data) );
{
  name: {
    value: ‘ajanuw‘,
    writable: true,
    enumerable: true,
    configurable: true
  },
  change: {
    value: [Function: change],
    writable: true,
    enumerable: true,
    configurable: true
  },
  message: {
    get: [Function: get message],
    set: undefined,
    enumerable: true,
    configurable: true
  }
}
class Ajanuw {
  name = "ajanuw";
  constructor() {
    this.name = "suou";
  }
  change() {
    this.name = "Ajanuw";
  }
  get message() {
    return "hello " + this.name;
  }
}
let data = new Ajanuw();
console.log( Object.getOwnPropertyDescriptors(data) );
console.log( Object.getOwnPropertyDescriptors( Object.getPrototypeOf(data) ) );
{
  name: {
    value: ‘suou‘,
    writable: true,
    enumerable: true,
    configurable: true
  }
}
{
  constructor: {
    value: [class Ajanuw],
    writable: true,
    enumerable: false,
    configurable: true
  },
  change: {
    value: [Function: change],
    writable: true,
    enumerable: false,
    configurable: true
  },
  message: {
    get: [Function: get message],
    set: undefined,
    enumerable: false,
    configurable: true
  }
}

js {}与class属性描述符的区别

标签:prototype   hello   cto   table   区别   prope   fine   set   als   

原文地址:https://www.cnblogs.com/ajanuw/p/14163363.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!