Basic JavaScript Question: Download JavaScript PDF

What is bind in javascript?

Tweet Share WhatsApp

Answer:

Functions are objects in JavaScript, as we should know well by now, and as objects, functions have methods, including the powerful Apply, Call, and Bind methods.

// Define the original function.
var checkNumericRange = function (value) {
if (typeof value !== \'number\')
return false;
else
return value >= this.minimum && value <= this.maximum;
}

// The range object will become the this value in the callback function.
var range = { minimum: 10, maximum: 20 };

// Bind the checkNumericRange function.
var boundCheckNumericRange = checkNumericRange.bind(range);

// Use the new function to check whether 12 is in the numeric range.
var result = boundCheckNumericRange (12);
document.write(result);

// Output: true

Download JavaScript PDF Read All 114 JavaScript Questions
Previous QuestionNext Question
What are decodeURI() and encodeURI() functions in JavaScript? How do use javascript to open a chatque on a webpage i have only when someone clicks from a specific link. i.e. when anybody click a specific link to go to said webpage. the javascript will see that it came from the specific link and run its function?