亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - JS在類別中聲明數(shù)組時(shí)出現(xiàn)問題
淡淡煙草味
淡淡煙草味 2017-05-19 10:25:21
0
2
783
var dynamic_particle=function(){
        this.init();
    }
dynamic_particle.prototype={
       init:function(){
           this.a=new Array();
           this.a.push(1);
           alert(a[0]);
        }
    }

a出現(xiàn)錯(cuò)誤為未定義

淡淡煙草味
淡淡煙草味

全部回覆(2)
僅有的幸福
var dynamic_particle=function(){
        this.init();
    }
dynamic_particle.prototype={
       init:function(){
           this.a=new Array();
           this.a.push(1);
           alert(this.a[0]);
        }
    }

你都知道前面用this.a ,alert的時(shí)候?yàn)楹尾患由?code>this.呢…一定報(bào)錯(cuò)

習(xí)慣沉默

封裝方式,一般是這樣使用的:

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('初始化數(shù)據(jù):', this.opt);
    },
    other: function() {
        console.log('調(diào)用option中的新數(shù)據(jù)', this.opt.newData);
    }
}
var dp = dynamic_particle({
    newData: [2] 
})
dp.other()
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板