收藏代码

 1 function Container(properties) {
 2             for (var property in properties) {
 3                 (function () {
 4                     var item = properties[property];
 5                     this["get" + property] = function () { return item; };
 6                     this["set" + property] = function (val) { item = val; };
 7                 }).call(this);
 8             }
 9 }
10 
11         var prop = { Name: "Jim", Age: 13 };
12         var con = new Container(prop);
13         console.log(con.getName());
14         console.log(con.getAge());

 

posted @ 2013-12-09 17:06  魔狼再世  阅读(473)  评论(0编辑  收藏  举报