坏小仔

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
function User( properties ) {
// Iterate through the properties of the object, and make sure
// that it's properly scoped (as discussed previously)
for ( var i in properties ) { (function(thiz){
// Create a new getter for the property
thiz[ "get" + i ] = function() {
return properties[i];
};
// Create a new setter for the property
thiz[ "set" + i ] = function(val) {
properties[i] = val;
};
})(this); }
}

this 必须传入闭包内。

posted on 2012-09-18 14:38  坏小仔  阅读(114)  评论(0编辑  收藏  举报