These three functions refer to the function itself, and the first parameter of call () and apply () are the context objects to be executed by the function, and then the arguments are the arguments that the function executes to be passed, and in different places, call is the parameter of the enumeration, and apply is passed as an array. Of course, you can also pass arguments objects. Bind () binds the function to the specified context context execution environment, simply by pointing the function's this object to the parameter context in bind () and returning a function instance.
Simply write an example code and we'll be clear:
<script>functionSayhi (name,greeting) {varName = name| | This. Name, greeting= Greeting| | This. Greeting; Console.log ("Hello" +name+ "," +greeting); } varName = "Terry", greeting= "How is it?", Me= {Name: "John", Greeting:Hello "}; Sayhi.call ( This, name,greeting); Sayhi.call ( This); Sayhi.apply ( This, [name,greeting]); Sayhi.apply (me,[me.name,me.greeting]); Sayhi.call (me,me.name,me.greeting); //bind () returns the function instance, followed by () to execute directlySayhi.bind () (); Sayhi.bind (Me) (); </script>
Execution Result:
Internal methods for Function objects call (), apply (), bind ()