function Animal(name) { this.name = name this._init() this._add()}Animal.prototype._init = function() { this.food = [] console.log(this.food)}Animal.prototype._add = function() { console.log(1) this.food.push('fish') this.food.push('mouse') console.log(2)}var a = new Animal('cat')執(zhí)行結(jié)果為:我的問(wèn)題是:_add方法在_init方法后執(zhí)行,為什么輸出this.food的時(shí)候已經(jīng)被賦值?想不明白,希望有人幫助我理解下b( ̄▽ ̄)d,感謝!
關(guān)于prototype內(nèi)方法的執(zhí)行
瀟湘沐
2019-03-07 14:15:28