JS
如何让JS实现类似PHP的 __set __get方法?
html
属性
javascriptprototype
回复内容:
JS
如何让JS实现类似PHP的 __set __get方法?
html
属性
javascriptprototype
估计你是想要这个:
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