function Fn() { this.x=100; this.y=200; this.getY=function(){ console.log(this.y); } } var f1=new Fn; var f3=null; cloneObj(f3,f1); console.log(f3); function cloneObj(obj1,obj2) { for (var key in obj2) { if (obj2.hasOwnProperty(key)) { console.log(obj2[key]); //100 obj1[key]=obj2[key]; //Cannot set property 'x' of null } } return obj1; }实在是不懂....打印的时候明明obj2[x]===100,为什么下一行就报错了?
添加回答
举报
0/150
提交
取消