Question

I'm new to lo-dash, and wanted to know is it possible to use _.bind as $.bind and how can I accomplish this? I really want to get rid of jQuery and use something smaller...

What I need is to bind DOM events to functions

Was it helpful?

Solution

Those are two different mechanisms.

_.bind sets the this value of a function to the first parameter so that 'this' will always point to the same object in the function. I'd say it binds the scope of 'this' to the function, except that would be incorrect technically.

$.bind adds a jquery triggered event listener to a jquery wrapped element.

There are plenty of dom selection alternatives (such as zepto.js), but lodash/underscore libraries are really in addition to jquery, not in lieu of jquery.

That being said, this may not necessarily answer your question, except to say zeptoJs might be one such alternative. Again, Underscore/Lodash is not an alternative to but one or the other provides additional functionality (that in the long term will save file size.)

fwiw imho. 37k is not a valid arguments against jquery/lodash and other such tools. why? 1) If you serve your libraries from a cdn its not even a valid hit against the server. 2) These libraries help you write WAY SMALLER code.

In fact this claim sounds more like an excuse than a reason.

cheers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top