“如何”;这";指JQuery中的DOM元素
对于这样的回调调用,“如何”;这";指JQuery中的DOM元素,jquery,this,Jquery,This,对于这样的回调调用,JQuery如何实现从window到DOM元素的引用 使用该方法完成 以下是代码的链接: 这一切都是关于范围的!通常,当前作用域中绑定到this的对象由当前函数的调用方式决定,在执行过程中不能通过赋值进行设置,每次调用函数时它都可能不同 EcmaScript 5引入了bind方法来修复函数的this,而不管它是如何调用的 当this关键字出现在函数内部时,其值取决于函数的调用方式 thecallback.apply(theelement,theeventobj
JQuery
如何实现从window
到DOM元素的引用 使用该方法完成
以下是代码的链接:
-
-
-
这一切都是关于范围的!通常,当前作用域中绑定到
this
的对象由当前函数的调用方式决定,在执行过程中不能通过赋值进行设置,每次调用函数时它都可能不同
EcmaScript 5引入了bind方法来修复函数的this
,而不管它是如何调用的
当this
关键字出现在函数内部时,其值取决于函数的调用方式
thecallback.apply(theelement,theeventobject)
jQuery使用call()
和apply()
在一定范围内更改this
的值,操作如下:
function() {
return this === window // true, "this" would be the window
}
function f2(){
"use strict";
return this; // "this" would return undefined in strict mode
}
var o = {
prop: 'test',
f: function() {
return this.prop; // here "this" would be the object o, and this.prop
// would equal o.prop
}
};
var t = o.f(); // t is now 'test'
你可以阅读更多关于,和其他的东西
thecallback.apply(theelement,theeventobject)
function() {
return this === window // true, "this" would be the window
}
function f2(){
"use strict";
return this; // "this" would return undefined in strict mode
}
var o = {
prop: 'test',
f: function() {
return this.prop; // here "this" would be the object o, and this.prop
// would equal o.prop
}
};
var t = o.f(); // t is now 'test'
function add(c, d){
return this.a + this.b + c + d;
}
var o = {a:1, b:3};
// The first parameter is the object to use as 'this',
//subsequent parameters are passed as
// arguments in the function call
add.call(o, 5, 7); // 1 + 3 + 5 + 7 = 16
// The first parameter is the object to use as 'this',
// the second is an array whose members are used
//as the arguments in the function call
add.apply(o, [10, 20]); // 1 + 3 + 10 + 20 = 34