IE6在大陸的肆虐,讓人不敢嘗試許多東西,像get,set這樣的好東西就是一個例子,因為它們在IE67就是語法錯誤,因此ecma262v5才搞出defineProperty這樣的東西。
用法很簡單,讓一個方法像屬性那樣使用!
var a = { bb: "xxx", get aa(){//不用寫function與: return this.bb+"!" } } console.log(a.aa) var fn = function(){ this.ee = "!!" } fn.prototype = { get dd(){//不用寫function與: return this.ee+"pp" } } var instance = new fn; console.log(instance.dd)
我已用到我的后端框架去了!