Javascript jQuery:$(this)与此。$()

Javascript jQuery:$(this)与此。$(),javascript,jquery,this,ember.js,Javascript,Jquery,This,Ember.js,在Ember.js中,它们有一个jQuery代码片段,语法如下: this.$().button(); 此代码段是否仅将此转换为jQuery对象,以便可以对其调用jQuery UI.button()函数 这个片段会是相同的吗 $(this).button(); 委员会解释如下: /** Returns a jQuery object for this view's element. If you pass in a selector string, this method w

在Ember.js中,它们有一个jQuery代码片段,语法如下:

this.$().button();
此代码段是否仅将
转换为jQuery对象,以便可以对其调用jQuery UI
.button()
函数

这个片段会是相同的吗

$(this).button();
委员会解释如下:

/**
    Returns a jQuery object for this view's element. If you pass in a selector
    string, this method will return a jQuery object, using the current element
    as its buffer.

    For example, calling `view.$('li')` will return a jQuery object containing
    all of the `li` elements inside the DOM element of this view.

    @param {String} [selector] a jQuery-compatible selector string
    @returns {Ember.CoreQuery} the CoreQuery object for the DOM node
  */
  $: function(sel) {
    return this.invokeForState('$', sel);
  },

因此,为了回答您的问题:不,它与
$(this)
不同,后者将余烬视图实例包装在jQuery对象中…

第一个片段建议将jQuery对象($)存储为
this
上的属性,可能是为了避免污染全局范围,但我不确定。但它是执行的。它又回来了,所以它被锁住了。我认为这是合法的,但我从来没有想过尝试…这个。按钮()有用吗?如果是这样,“this”是一个jquery对象。好吧,我刚刚测试了“将jquery()作为函数随机设置this”,当然,正如预期的那样,这不起作用,谢谢。这正是我想要的答案。