84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
var dynamic_particle=function(){ this.init(); } dynamic_particle.prototype={ init:function(){ this.a=new Array(); this.a.push(1); alert(a[0]); } }
a error is undefined
var dynamic_particle=function(){ this.init(); } dynamic_particle.prototype={ init:function(){ this.a=new Array(); this.a.push(1); alert(this.a[0]); } }
You all know how to use this.a before. Why not add this. when using alert... an error will definitely be reported
this.
var defOpt = { a: [1] } var dynamic_particle=function(options){ if(!(this instanceof dynamic_particle)){ return new dynamic_particle(options); } this.opt = $.extend({}, defOpt, options); this.init(); } dynamic_particle.prototype={ init:function(){ console.log('初始化数据:', this.opt); }, other: function() { console.log('调用option中的新数据', this.opt.newData); } } var dp = dynamic_particle({ newData: [2] }) dp.other()
You all know how to use this.a before. Why not add
this.
when using alert... an error will definitely be reportedEncapsulation method is generally used like this: