Sometimes you use a pattern so frequently that you don’t realize that other people might not know about it. Here’s the most recent one for me — I was surprised that this wasn’t being used in the last few codebases I’ve seen:
If you’re using Backbone.js, instead of writing
view.$el.find('span.timestamp')
or worse
$(view.el).find('span.timestamp')
or
$('span.timestamp', view.$el)
Backbone provides a $ method such that you can simply write
view.$('span.timestamp')
It’s less to type and it doesn’t hurt readability.
I was google-ing for this issue but couldn’t find correct answer anywhere.
Your post helped me a lot.
Thanks.
August 23, 2012 at 1:13 am
Elegant solution. Thank you!
September 27, 2012 at 12:29 am