Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.js - difference between this.$(selector) and this.$el.find('selector')

Tags:

backbone.js

As per title, what is the difference (if any) in a backbone view between saying:

this.$('.foo');

and

this.$el.find('.foo');

They both return the element and appear to scope it to the current view but I've seen examples using both methods.

Thanks

like image 596
user1781543 Avatar asked Jan 22 '13 15:01

user1781543


1 Answers

The difference is precisely none whatsoever. The method in Backbone source code is declared as:

$: function(selector) {
  return this.$el.find(selector);
}
like image 108
jevakallio Avatar answered Oct 20 '22 00:10

jevakallio