![]() |
what is bind() method in javascript?
what is bind() method in javascript?
|
hello friends,
Let's look at a non Javascript example to help understand objects, methods, and propreties. Consider a a pet like a cat or a dog. What are some functions or tasks that a cat object might perform? Cats eat, sleep, scratch, meow, run, hunt, and other things. In Javascript lingo, each of these verbs would be methods of the cat object. These methods would be written as: cat.eat("cat food") cat.sleep() cat.scratch("furniture") cat.meow() Notice that methods have parentheses after them and that some methods require information within the parentheses. Informaton within a method's parentheses is known as the method parameter(s). A parameter is just additional information that a method needs to do its job. In the Javascript world the write method of the document object needs to know what to write so the method has a parameter that tells it what to write. Similarly the parameter of the prompt method tells the method what to display in the dialog box. |
Bind is a method inherited from Function.prototype same like call and apply. It basically helps to bind a function to an object's context during initialization.
See More at krasimirtsonev[dot]com/blog/article/JavaScript-bind-function-setting-a-scope |
The bind() method creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.
|
All times are GMT -7. The time now is 03:33 PM. |
Powered by vBulletin Copyright © 2020 vBulletin Solutions, Inc.