歡迎糾正和補充c++
function fn() { console.log(this); } window.fn();
var obj = { fun: function () { console.log(this); } } obj.fun();
var gf = { name : "tangwei", bar : "c++", sayWhat : function() { console.log(this.name + "said:love you forever"); } }
btn.onclick = function () { console.log(this); }
setInterval(function() { console.log(this); }, 1000);
總結:函數內部的this,是由函數調用的時候來肯定其指向的函數