Javascript类库中和编程语言中getter和setter
1.backbonejs中的getter和setter
所说的backbonejs中的getter和setter就是内部自定义get和set方法,set方法嵌入了Pub/Sub模型
,
例如 book.on("change:title change:author", ...);
当book.set('title':'othertitle');
触发change
对用的function
,
解开二重锁 (不等于自身和并且非正在执行change function)。
2.YUI中的getter和setter
get: http://yuilibrary.com/yui/docs/api/files/attribute_js_AttributeCore.js.html#l343
Y.augment : http://yuilibrary.com/yui/docs/api/files/oop_js_oop.js.html#l67
3.javascript中的getter和setter
4.java中的getter和setter
总结:
用function封装存储规则,在set,get中嵌入pub/sub模式实现 事件触发。
参考文献:
1.http://ejohn.org/blog/javascript-getters-and-setters/
2.javascript权威指南 6.6 属性getter和setter
-EOF-
原创文章,版权声明:自由转载-非商用-非衍生-保持署名 | Creative Commons BY-NC-ND 3.0