JS 的defineProperties 设置多个属性

var book = {};
//用Object.defineProperties()方法设置多个属性
Object.defineProperties(book,{
    _year:{
        value:"ry",
        writable: true
    },
    _author:{
        value:'better2017',
        writable: true
    },
    edition:{
        value:1
    },
    year:{
        get:function(){
            return this._year ;
        },
        set:function(newValue){
            this._year = newValue;
        }
    },
    author:{
        get:function(){
            return this._author;
        },
        set:function(newValue){
            this._author = newValue;
             
        }
    }
});

 

相关文章:

  • 2021-09-02
  • 2022-12-23
  • 2022-03-02
  • 2022-12-23
  • 2022-01-27
  • 2022-01-25
  • 2022-01-13
  • 2021-04-14
猜你喜欢
  • 2022-02-24
  • 2022-01-21
  • 2021-11-29
  • 2022-01-08
  • 2021-08-12
相关资源
相似解决方案