4 ms·
A native method for binding methods has existed for a long time and is called just that: f = obj.doSomething.bind(obj); Wrapping functions like in th
by esailija 14y ago
A native method for binding methods has existed for a long time and is called just that:
f = obj.doSomething.bind(obj);
Wrapping functions like in the example is different and is very common among cargo cultists
- mistercow 14y ago>A native method for binding methods has existed for a long time and is called just that: Well, bind is a relatively recent addition. It wasn't added to IE until IE9, and it wasn't added to Safari until March 2012. In any case, I think that f = (data) -> obj.doSomething data is far more readable than f = obj.doSomething.bind obj Edit: it's also worth mentioning that in Chrome and FireFox, at least, the latter version of f is an order of magnitude slower than the former (http://jsperf.com/native-vs-non-native-bind http://jsperf.com/native-vs-non-native-bind) But yes, wrapping functions is usually (but not always) silly.