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)

我已用到我的后端框架去了!

相关文章:

  • 2022-02-21
  • 2021-12-04
  • 2022-01-22
  • 2021-12-06
  • 2021-07-21
  • 2021-07-31
  • 2022-01-04
猜你喜欢
  • 2022-01-16
  • 2021-07-10
  • 2022-12-23
  • 2021-04-09
  • 2021-12-02
  • 2022-02-05
相关资源
相似解决方案