又见识一种另类js函数写法

 showUserInfo: function(data){
(function(P){
P.lblName.html(P.uid);
P.imgPhoto.attr('src', P.res + '/images/def_pic.gif');
imgurl = P.data.ImageUrl,
P.lblName.text(pName);......
})({
uid: top.uid,
lblName: $('#lblTrueName'),
imgPhoto: $('#imgPerson')
});
}

把依赖到的其他地方的变量,集中传参数进去,这样,内部的代码段更内聚,更容易迁移。


posted on 2011-10-24 17:00  伊伦  阅读(335)  评论(0编辑  收藏  举报

导航