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?

2

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.