1
- Function . prototype . myCall = function ( thisArg , ... args ) {
1
+ Function . prototype . myApply = function ( thisArg , args = [ ] ) {
2
2
thisArg = thisArg || globalThis ;
3
3
4
4
const uniqueId = Symbol ( 'fn' ) ;
@@ -10,7 +10,7 @@ Function.prototype.myCall = function(thisArg, ...args) {
10
10
return result ;
11
11
}
12
12
13
- Function . prototype . myCall1 = function ( thisArg , ... args ) {
13
+ Function . prototype . myApply1 = function ( thisArg , args = [ ] ) {
14
14
const uniqueId = Symbol ( 'fn' ) ;
15
15
const wrappedObj = Object ( thisArg ) ;
16
16
Object . defineProperty ( wrappedObj , uniqueId , {
@@ -21,11 +21,11 @@ Function.prototype.myCall1 = function(thisArg, ...args) {
21
21
return wrappedObj [ uniqueId ] ( ...args ) ;
22
22
}
23
23
24
- Function . prototype . myCall2 = function ( thisArg , ... args ) {
25
- return this . apply ( thisArg , [ ...args ] ) ;
24
+ Function . prototype . myApply2 = function ( thisArg , args = [ ] ) {
25
+ return this . call ( thisArg , ...args ) ;
26
26
}
27
27
28
- Function . prototype . myCall3 = function ( thisArg , ... args ) {
28
+ Function . prototype . myApply3 = function ( thisArg , args = [ ] ) {
29
29
return this . bind ( thisArg , ...args ) ( ) ;
30
30
}
31
31
@@ -38,7 +38,7 @@ function details(age = 30) {
38
38
return this . firstName + ' ' + this . lastName + ' is ' + age + ' years old' ;
39
39
}
40
40
41
- console . log ( details . myCall ( person1 , 35 ) ) ;
42
- console . log ( details . myCall1 ( person1 , 35 ) ) ;
43
- console . log ( details . myCall2 ( person1 , 35 ) ) ;
44
- console . log ( details . myCall3 ( person1 , 35 ) ) ;
41
+ console . log ( details . myApply ( person1 , [ 35 ] ) ) ;
42
+ console . log ( details . myApply1 ( person1 , [ 35 ] ) ) ;
43
+ console . log ( details . myApply2 ( person1 , [ 35 ] ) ) ;
44
+ console . log ( details . myApply3 ( person1 , [ 35 ] ) ) ;
0 commit comments