-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbind.js
36 lines (29 loc) · 797 Bytes
/
bind.js
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
// Import stylesheets
import './style.css';
// Write Javascript code!
// const appDiv = document.getElementById('app');
// appDiv.innerHTML = `<h1>JS Starter</h1>`;
const obj = {
firstname: 'Shreya',
lastname: 'Varma',
printName: function (city, state) {
console.log(this.firstname, this.lastname, city, state);
},
};
obj.printName('Dhule', 'MH');
const obj2 = {
firstname: 'Jyoti',
lastname: 'Varma',
};
const print = obj.printName.bind(obj2, 'Nagpur');
// const printName2 = obj.printName.bind(obj2);
print('MH');
Function.prototype.myBind = function (...args) {
let obj = this;
let params = args.slice(1);
return function (...args2) {
obj.apply(args[0], [...params, ...args2]);
};
};
const printName2 = obj.printName.myBind(obj2, 'pohana');
printName2('MH');