提问:我用JS封装了一个类,封装方式var dragbox = function (config, returntype) { var dom = this.init(config); // return dom;} //构造函数classtest.prototype={……},为什么这个类的实例化参数会有公用问题?就是我第一实例化的参数 ,会沿用到第二个实例化的参数,做对比就是我类中有个辅助函数jsonclone: function (old_object, new_object) { for (var key in new_object) { if (typeof old_object[key] != typeof new_object[key]) { console.warn(key + "类型错误"); return; } else if (typeof old_object[key] == "object") { this.jsonclone(old_object[key], new_object[key]); } else if (old_object[key] != undefined) { old_object[key] = new_object[key]; } } }init:function (config) { if (config == undefined || config == null) { console.log("未初始化"); return; } var othis = this; this.jsonclone(this.config, config); this.dragdom = this.init_create(); // return this.dragdom;}这个类在第二次实例化的时候,类的config里参数变成第一次实例化的参数,这是为什么??是我构建类的方法不对么?
1 回答

GCT1015
TA贡献1827条经验 获得超4个赞
实例化的 new 一下
var config1 = {};
var config2 = {};
var demo1 = new dragbox(config1, null);
var demo2 = new dragbox(config2, null);
添加回答
举报
0/150
提交
取消