[英]Why isnt “this” work with console.log as an argument?
我以為.call應該//將log方法中的上下文更改為obj,但是似乎並沒有這樣做,似乎是在引用window對象,就像我在這邊使用了一個函數一樣。
let obj={
a: "this should work right?"
}
console.log.call(obj,this.a);//returns undefined
您不在函數范圍內,而是應該這樣測試:
let obj={
a: "this should work right?"
};
let myFunc = function() { // u define a function scope here
return this.a;
};
console.log(myFunc.call(obj));
// console.log.call(obj,this.a);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.