时间:2021-07-01 10:21:17 帮助过:17人阅读
如何让JS实现类似PHP的 __set __get方法?
html
javascript
prototype
如何让JS实现类似PHP的 __set __get方法?
html
javascript
prototype
估计你是想要这个:
username.__defineGetter__('_tipsTxt', function(){return this.getAttribute('_tipsTxt');});
username.__defineSetter__('_tipsTxt', function(txt){this.setAttribute('_tipsTxt', txt);});
JS属性自带set
,get
功能啊..=_= 请看DEMO:http://jsfiddle.net/7jfmafkd/
具体请查阅:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty