Site Owners Forums - Webmaster Forums

Site Owners Forums - Webmaster Forums (http://siteownersforums.com/index.php)
-   Programming General (http://siteownersforums.com/forumdisplay.php?f=44)
-   -   what is bind() method in javascript? (http://siteownersforums.com/showthread.php?t=164238)

Manishkumar12 01-27-2016 12:17 AM

what is bind() method in javascript?
 
what is bind() method in javascript?

hdensr 01-31-2016 10:07 PM

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.

Shivangi Panwar 01-31-2016 11:24 PM

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

Martinricky 02-01-2016 01:30 AM

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.