//call
let obj = {
name: 'Rajdeep'
}
let newFunc = function(c){
console.log(this.name + ' ' + c)
}
// with .call we can call and obj from a method
//in below we are calling the name property of obj from the newFunc method
newFunc.call(obj,'chandra');
//bind
let obj1 = {
name: 'Subhodeep'
}
let newArr = ['a', 'b', 'c']
let applyFunc = function(a, b, c) {
console.log(this.name + ' ' + a + b + c)
}
// with .call we can apply an obj from a method
//in below we are calling the name property of obj1 from the newFunc method, here the parameters should be array like newArr
applyFunc.apply(obj1, newArr);
//bind
let obj2 = {
name: 'Subhodeep'
}
let bindFunc = function(a) {
console.log(this.name + a)
}
// with .bind we can bind an obj from a method
//in below we are calling the name property of obj1 from the newFunc method
var bound = bindFunc.bind(obj2);
bound('8');
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.