In Ember.js's docs, they have a jQuery code snippet with the following syntax:
this.$().button();
Is this snippet only turning this
into a jQuery object so that the jQuery UI .button()
function can be called on it?
Would this snippet be identical?
$(this).button();
In Ember.js's docs, they have a jQuery code snippet with the following syntax:
this.$().button();
Is this snippet only turning this
into a jQuery object so that the jQuery UI .button()
function can be called on it?
Would this snippet be identical?
$(this).button();
Share
Improve this question
edited Jun 18, 2012 at 21:24
Noah Freitas
asked Jun 18, 2012 at 21:13
Noah FreitasNoah Freitas
17.4k11 gold badges51 silver badges67 bronze badges
4
|
1 Answer
Reset to default 26The source code explains this as follows:
/**
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);
},
So to answer your question: no it's not the same as $(this)
, which would wrap the ember view instance in a jQuery object...
this
, possibly to avoid polluting global scope, but I'm not sure. – chrisfrancis27 Commented Jun 18, 2012 at 21:16