我已经看过关于jQuery与$(this)vs的一些讨论$this,它们对我来说很有意义。(有关示例,请参见此处的讨论。)
但是下面的jQuery网站插件教程中的片段如何显示可链接性呢?
(function ($) {
$.fn.lockDimensions = function (type) {
return this.each(function () {
var $this = $(this);
if (!type || type == 'width') {
$this.width($this.width());
}
if (!type || type == 'height') {
$this.height($this.height());
}
});
};
})(jQuery);
$this以上代表什么?就在我想知道了的时候...
var $this = $(this);-不必this每次调用jQuerify只是一种捷径。