Hacker News new | past | comments | ask | show | jobs | submit login

How often do you use call and apply? I've been a JS developer for a long time, have written a lot of JS code, and rarely need to use call and apply.

Unless you're writing all your code from scratch and not using any frameworks / util libs (which you should) you won't need them very often.




Agreed I can't even recall the last time I used call or apply. We might have only a handful of cases out of roughly 200,000 JS lines of code.


Perhaps that is why y'all have 200k LOC of javascript :)


Fairly often. Since the selected DOM element is the value of this in any event handler callback, you can migrate out the function and use it for different things (i.e. validation of, say, autofill after a settimeout) and different contexts with call/apply.


I don't see how this requires you to know the intricacies of call/apply or how it would even force you to use it frequently enough to understand the difference.


I guess I don't understand. There's a lot of ways to accomplish tasks in any programming language but in JS in particular there's a way to assign the value of this and you can use it to have clean, dry code, and I'd expect any sr. level people to know how to use it. jQuery source has over 100 uses of call and apply.


> jQuery source has over 100 uses of call and apply.

Right, jQuery does it for you. You usually don't need to do it yourself unless you're contributing to jQuery (or another lib/framework that needs them).

I might ask someone about call and apply but wouldn't be overly concerned if they didn't remember the exact syntax or mixed them up. I've done the same myself. I wouldn't expect someone to remember every little nuanced part of a language, especially if it's not something they use frequently.


If you do meta-programming in JavaScript you use call/apply all of the time.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: