有时候,我遇到了一段像这样的javascript代码:
function someFunc() {
var that = this;
// do something with that
}
为什么人们在使用'this'时会这样做?
答案 0 :(得分:1)
检查此示例:
function someFunc() {
var that = this;
$('.test').on('click', function() {
//in this scope the this will be different and if you'd like to use the this of someFunc then you need to assign another variable
})
}