It's pretty good code. Well done! There are no major mistakes or pain points that would annoy other developers. All I can do is to nitpick a little bit.
First of all take a look at some JavaScript style guide. jQuery has a good one and Google has a great one, too. You may find many others and although they all diverge a little bit there are a lot of common practices that they all agree on. One of those is braces' positioning. Instead of
render: function() {
you'd better use
render: function () { // note the spaces, too :)
Another point is the use of
===
instead of==
. I've noticed that you've never used a triple-equals operator in your code and I'm a little bit nervous. Maybe you know about the one vs. the other and you know what are you doing in this particular code (and btw your code works totally fine with double-equals). But what if you don't know? And what if some other developer who doesn't know JavaScript well take a look at your code and try to do something similar? Suppose he doesn't know the rules and you code is the largest and most complicated piece of JavaScript he's ever seen. Which way of thinking do you think is more bullet-proof for a JS-newbie:JavaScript is somewhat weird: I have to use
===
to compare things.or
JavaScript is so easy! I'll use
==
to compare stuff everywhere in my code!I guess the former is better.
I noticed you use
.bind()
method for event binding. Consider switching to new.on()
method introduced in jQuery 1.7. One of the current goals for jQuery team is to make their library smaller and more lightweight so they work hard to cut off all the fat that's accumulated over the years. At some point in future they may remove the old API so it's better start using new API today to make your code future-proof. It''l be a lot less hassle to switch to new version of jQuery in future.
Other than that your code is fine. I really like the fact that you use Underscore JS. That saves you and other developers a lot of time and headaches.
- 186
- 4