-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCallBindApply.js
More file actions
31 lines (25 loc) · 848 Bytes
/
CallBindApply.js
File metadata and controls
31 lines (25 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// CALL
function hello(){
return "Hello" + this.name
}
var obj = { name : 'Kishan' }
console.log(hello.call(obj))
//call() method allows an object to use the method of another object
//APPLY
function Apply(message){
return this.name + ", " + message
}
var person = { name : "kishan" }
console.log(Apply.apply(person,["Awesome"]))
//Call method takes arguments saparately whereas , apply() method takes arguments as an array
//BIND
//This method return a new function where the value of this keyword will be bound to the another object
//, which provided as a parameter
var details = {
display : function(number, brand){
return this.name + " , " + "bike details " + number + brand
}
}
var person = { name : "kishan" }
var fetchDetail = details.display.bind(person,"OD#4343HNS", "Bajaj");
console.log(fetchDetail())