收藏代码

 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());
原文地址:https://www.cnblogs.com/mlzs/p/3465738.html