How can I define a default getter and setter using ECMAScript 5?

前端 未结 6 805
忘了有多久
忘了有多久 2020-12-07 01:14

How can I specify a default getter for a prototype? With default getter I mean a function that is called if obj.undefinedProperty123 is called.

I tried

6条回答
  •  [愿得一人]
    2020-12-07 01:44

    You need to wait for the implementation of the ECMA6 "Proxy" system, designed to do exactly this. See http://wiki.ecmascript.org/doku.php?id=harmony:direct_proxies.

提交回复
热议问题