Reputation: 1254
In the angular documentation it says that you can take an object and bind it to a function with optional arguments like this:
angular.bind(self, fn, args);
If I understood correctly "self" becomes "this" for the returned (and modified) fn.
This is also easily done with core javascript:
fn.apply(obj, args);
Am I missing something here?
Upvotes: 1
Views: 58
Reputation: 222310
angular.bind
creates a wrapper function with specified context.
It is a counterpart of Function.prototype.bind
, not Function.prototype.apply
.
angular.bind
is there from old days when it was good manners for JS libraries to be self-sufficient and not rely on standards and polyfills (a tribute to jQuery and jQuery.proxy
). This often resulted in smaller footprint.
angular.bind
and fn.apply
won't work with new
ed ES6 classes, it is preferable to stick to fn.bind
if it fits the case.
Upvotes: 2