zoukankan      html  css  js  c++  java
  • js {}与class属性描述符的区别

    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
      }
    }
    
  • 相关阅读:
    敏感性分析与风险分析
    深入理解PHP之foreach
    PHP上传文件到七牛(Qiniu)
    Swoft 新手向教程
    HP下kafka的实践
    关于BOOTSTRAP的整理和理解
    win10 ubuntu 子系统安装php
    CentOS7 安装 PHP7.2
    PHP 锁机制
    深入理解PHP之strpos
  • 原文地址:https://www.cnblogs.com/ajanuw/p/14163363.html
Copyright © 2011-2022 走看看