1

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?

brainmassage
  • 1,234
  • 7
  • 23
  • 42

1 Answers1

2

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 newed ES6 classes, it is preferable to stick to fn.bind if it fits the case.

Estus Flask
  • 206,104
  • 70
  • 425
  • 565