在此查询中,我有一个小疑问,我需要知道为什么?
我们处于#lockdown的状态,而我的一个兄弟padu提出了这个问题。在下面的示例对象中,有一些函数在直接调用其返回1时分配,而在分配为const并以函数访问的方式返回undefined。有人有任何解释将有助于提高我的知识。
const apple = 3;
const data = {
apple: 2,
bag: {
apple: 1,
plastic: function(){
return this.apple;
}
}
}
const plastic = data.bag.plastic;
console.log(plastic()) **//Result - undefined**
console.log(data.bag.plastic()) **//Result - 1**
谢谢,
Gopal.R
您正在搜索bind()
bind()