Angular. bind usage experience, angularngbindhtml
Angular. bind
Explanation: return a function fn that calls self (self represents this In fn). The args (*) parameter can be provided to fn. this function is also called a local operation to differentiate functions.
Format: angular. bind (self, fn, args );
Self: object; fn context object, which can be called using this In fn
Fn: function; binding method
Args: Input fn Parameters
var obj = { name: "Any" }; var fn = function (Adj) { console.log(this.name + "is a boy!!! And he is " + Adj + " !!!"); }; var f = angular.bind(obj, fn, "handsome"); f();//Any is a boy!!! And he is handsome!!! var t = angular.bind(obj, fn); t("ugly");// Any is a boy!!! And he is ugly!!!
Let's talk about angular. bind ~
As the name implies, bind is bound. If we want to bind A to B, there must be two other entities, A and B. The two objects required here are an object and a function. So how to bind it? @ The understanding of the beast is to "bind" the object to this function for execution. At this time, this of fn is equal to obj. As for the third parameter, this parameter is optional, if the function needs to input parameters, we can set angular. put the third parameter of bind, which is the input parameter of the fn function.
In this case, the first method is to pass the parameters required by fn when defining the binding, and use them directly when calling the function. In this case, the second method is to bind the function first, when the call is executed, the fn parameter is passed again, and the effect is the same.
For the above English sentence (well, although there are only two sentences), if something is wrong, it means that we love our native language-Chinese. If you accidentally write it right, so please applaud the installation of 66666 B ~
At the end of the article, let's look at an example.
<! Doctype html>