4 ms·
Call and apply are core concepts to writing good javascript. I would not hire someone (at least for any sort of senior role) that could not tell you exactly ho
by cozuya 12y ago
Call and apply are core concepts to writing good javascript. I would not hire someone (at least for any sort of senior role) that could not tell you exactly how both of them work. Many of the other things on this page are certainly "trivia" that could be addressed by google when they come up, but not those.
- serve_yay 12y agoWell, they are both exactly the same. The only difference is the particular way each accepts arguments, and it's easy to forget which is which. So yes you should know how they work, but the distinction between them is contingent and difficult to remember.
- tericho 12y agoLike most JS concepts, to me it's a "use it or lose it" situation. When I have to use them they are fresh in my head, when I move on to another project for 6 months that has no complex modules or uses a framework like Angular, there is no way I'll remember the intricacies. That being said, there is still a different between having used them and simply being aware of their existence, which I suppose could be made clear during an interview.
- alxndr 12y agoThis sounds like a very good answer to that question.
- FLUX-YOU 12y ago>Call and apply are core concepts to writing good javascript. But the biggest issue is the disagreement with the body of knowledge that everyone should have. Even in the body of knowledge, there's disagreements about what bits of knowledge go to which categories (Is it nice-to-know, or need-to-know?) It's really no wonder you see such a broad range of candidate skills and knowledge. The sub-fields of the programming field can't even decide what everyone ought to know at various levels of experience!
- lsdafjklsd 12y agoI agree, but I'll say that it wasn't until I started writing non-ember application code (switching to react + immutable.js + pure functions) that I needed things like call / apply / bind on the regular. So writing framework code can really insulate you from needing these things, not implying that that's a bad thing, but personally writing regular javascript has been a breathe of fresh air.
- deleted 12y ago[deleted]
- driverdan 12y agoHow 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.
- cozuya 12y agoFairly 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.
- tericho 12y agoI 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.
- cozuya 12y agoI 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.
- driverdan 12y ago> 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.