-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathBindApplyCallPolyfill.js
More file actions
67 lines (44 loc) · 1.19 KB
/
BindApplyCallPolyfill.js
File metadata and controls
67 lines (44 loc) · 1.19 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Polyfill for bind?
function callMe (s , s1 , s3) {
console.log(s , s1 , s3)
console.log(this.name , ' ' ,this.lastName)
}
// thousand of the object
const objet1 = {
name:"Adam" ,
lastName: "Gilkhrist"
}
const objet2 = {
name:"Vishal" ,
lastName: "Sharma"
}
// const bindFunc = callMe.bind(objet1 , 'you...');
// bindFunc('hello' , 'ye')
//mybind ??
Function.prototype.mycall = function(obj , ...args) {
// this ??=> calling function
obj.callFunc = this;
obj.callFunc(...args)
}
Function.prototype.myApply = function(obj , args) {
// this ??=> calling function
obj.callFunc = this;
obj.callFunc(...args)
}
Function.prototype.myBind = function(object , ...args) {
let func = this; // func reference
return function(...arg1) {
// func.myApply(object , [...args , ...arg1]);
func.mycall(object , [...args , ...arg1])
}
}
const myBindFunc = callMe.myBind(objet1 , 'array1' , 'array2');
myBindFunc('array3');
// const object = {};
// object.func = function () {
// console.log(this.name , this.lastName)
// }
// object.name = "Dhoni"
// object.lastName = "Singh"
// object.func();
// polyfill apply ??