素胚勾勒不出你
2019-03-12 13:15:16
function Parent() {}Parent.prototype.func1 = function(callback) { this.callback = callback;}Parent.prototype.func2 = function() { this.callback.fetchData()}在構(gòu)造函數(shù)中,是不是func1定義的屬性,如this.callback。在func2中也可以訪問?
3 回答

Qyouu
TA貢獻1786條經(jīng)驗 獲得超11個贊
可以 構(gòu)造函數(shù)中的this是實例對象,這些屬性是掛在實例對象上的。
function Parent() {
}
Parent.prototype.func1 = function(callback) {
this.callback = callback;
}
Parent.prototype.func2 = function() {
console.log(this.callback)
this.callback.fetchData()
}
Parent.prototype.func1({fetchData: function(){
console.log(2)
}})
let per = new Parent()
per.func2()
添加回答
舉報
0/150
提交
取消