var data = {
items: ['a', 'b', 'c'],
get length () {
return this.items.length;
},
set first (val) {
this.items[0] = val;
}
};
console.log(data.length); // 3
data.length = 4; // 严格模式下报错:Uncaught TypeError: Cannot set property length of #<Object> which has only a getter(…)
console.log(data.first = 'd');
console.log(data.items); // ["d", "b", "c"]
var MyDate = function() {}