Reputation: 500
can I use $.each() method instead of _each() in backbone implementation code . is there any performance improvements for the same code by using underscore methods?
Upvotes: 1
Views: 79
Reputation: 16041
You can use jQuery in Backbone without any issues. Backbone itself has chosen to use Underscore, because it is a more lightweight solution, and Backbone aims to be minimal library. (In this case, by lightweight, I mean that the minified Underscore library is about 5kB, the latest jQuery is nearly 100kB in size.)
You are not forced to use Underscore yourself, if you need jQuery for some reason, then by all means, use it. As for performance: you can't really say anything in general, you have to make measurements if you want meaningful results.
Upvotes: 0
Reputation: 7429
underscore.js is part of backbone, so it's already included ;)
If youre interested in performance, have a look at this
http://jsperf.com/test-jquery-each-vs-each
underscore is a bit faster
Upvotes: 1
Reputation: 6057
Either or will do, according to http://jsperf.com/jquery-each-vs-underscore-each-vs-for-loops/4, just using plain for loops is faster, but the underscore method preformed better. I suggest you try your own tests as well, because this is only a single tests cas eon a single platform, you may find different results.
Upvotes: 0