4.9 this 關鍵字
在 javascript/practice
資料夾下,建立 this.html
檔案,以便練習。
範例1
//"use strict";
console.log(this); // window
"use strict";
console.log(this); // window
範例2
//"use strict";
function test(){
console.log(this); // window
}
test();
"use strict";
function test(){
console.log(this); // undefined
}
test();
範例3
//"use strict";
var myobj = {
data: "my_str",
test: function(){
console.log(this); // myobj
}
};
myobj.test();
"use strict";
var myobj = {
data: "my_str",
test: function(){
console.log(this); // myobj
}
};
myobj.test();
Last updated