这个问题最好用代码解释:
let c = 1;
let d = 2;
function show() {
console.log(this.c, this.d);
}
// show() returns "undefined undefined"
var a = 1;
var b = 2;
function display() {
console.log(this.a, this.b);
}
// display() returns "1 2"
为什么是这样?
这个问题最好用代码解释:
let c = 1;
let d = 2;
function show() {
console.log(this.c, this.d);
}
// show() returns "undefined undefined"
var a = 1;
var b = 2;
function display() {
console.log(this.a, this.b);
}
// display() returns "1 2"
为什么是这样?