这个和$(this)在小部件中

Raj*_*l 웃 3 javascript jquery jquery-ui jquery-ui-widget

这个和$(this)在像widget这样的widget方法中意味着什么?

例如,拥有这样的小部件,

$.widget("sample.CustomWidget", {
options:{
},
_create: function(){
// Here what do this and $(this) mean
}
});
Run Code Online (Sandbox Code Playgroud)

提前致谢,

-Raja.

mam*_*moo 5

它基本上取决于_create方法的调用者......无论如何:

  • this 指的是函数的"所有者"

  • $(this) 是将上面的对象包装到jQuery对象中

也可以看看:

http://www.quirksmode.org/js/this.html

http://www.bennadel.com/blog/1838-Wrapping-The-Window-Object-In-A-jQuery-Wrapper.htm

  • 是的,但是在小部件的上下文中,"this"是一个JQuery小部件本身,而不是包装器. (2认同)