3 ms·
If you're writing a function that uses "this"... and using "bind" at where the function expression is written, you should just name the object itself and refer
by SamReidHughes 12y ago
If you're writing a function that uses "this"... and using "bind" at where the function expression is written, you should just name the object itself and refer to it in the function body that way. If you're defining the function one place with the expectation that "this" is bound to the right thing by code in another place, you should make your function take an explicit argument and pass it that way. That's how.
- ricardobeat 12y agoThat would still be a satisfactory answer, and demonstrate that the person has the necessary knowledge. You need to know how to manipulate `this` before you can reach the [subjective] conclusion that it is bad code.
- SamReidHughes 12y agoThe thing is, if you're interviewing and throwing away candidates because you're expecting knowledge of stuff that, for example, doesn't work in IE 6, or is based on your specific way of writing Javascript code, you're just throwing away good candidates. (Also, coding standards are not subjective. Some ways of writing code are more productive than others. The idea that it's subjective is nice to believe, because then you can pretend that nobody is wrong.)
- byoung2 12y agoI would question anyone who cites IE6 as a reason for coding a certain way in 2015. IE6 hasn't been relevant for at least 5 years now. But if a candidate said that he was familiar with bind() but would avoid it for the sake of compatibility with IE6 that at least shows familiarity with it. Using your logic, it would be ok for a candidate to say he had never heard of transparent PNGs because IE6 doesn't support them.
- SamReidHughes 12y agoI'm citing it as a reason for somebody not being familiar with it. IE6 certainly was a restriction in some environments in the past five years or less. And that's on top of the reason that there's no good reason to use bind in what many people consider to be reasonably written code. Knowledge of these sorts of library features is a terrible proxy for actual ability to write good Javascript. There are better ways to test for that in a phone screen.
- jtheory 12y agoIt's still relevant today, unfortunately, in some industries where upgrading is prohibitively expensive. E.g., you'd need to buy a new POS system, or paid millions to have custom-made medical software recertified (or re-written) to work on a newer browser, etc.. It's much rarer -- most places have bitten the bullet by now -- but I still see it (and IE7 is certainly still around).