JS高级代码

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;
             
        }
    }
});
原文地址:https://www.cnblogs.com/tianxue/p/7776659.html