-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbind.js
More file actions
36 lines (32 loc) · 1.38 KB
/
Copy pathbind.js
File metadata and controls
36 lines (32 loc) · 1.38 KB
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
32
33
34
35
36
'use strcit'
const obj = {
a:1,
b:5,
c: function(arg1, arg2) {
console.log(this)
console.log(`The given values are ${this.a} and ${this.b}. Arguments are ${arg1} and ${arg2} `)
}
}
// const x = obj.c;
// x(10,12);
const x = obj.c.bind(obj)
x(10,12);
/*
* ----------------------------------------------------------------------------------------------------
* With the bind() method, an object can borrow a method from another object.
* Bind returns a new function, allowing you to pass in a this array and any number of arguments.
* ----------------------------------------------------------------------------------------------------
*/
/*
The this keyword refers to different objects depending on how it is used:
-In an object method, this refers to the object.
-Alone, this refers to the global object.
-In a function, this refers to the global object.
-In a function, in strict mode, this is undefined.
-In an event, this refers to the element that received the event.
-Methods like call(), apply(), and bind() can refer this to any object.
-------------------------------------------------------------------------------------------
With the bind() method, an object can borrow a method from another object.
Bind returns a new function, allowing you to pass in a this array and any number of arguments.
-------------------------------------------------------------------------------------------
*/