-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapply.html
41 lines (41 loc) · 862 Bytes
/
apply.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
Function.prototype.myApply=function(context){
var context=context||window, result;
console.log(this)
context.fn=this;
if(arguments[1]){
result=context.fn(...arguments[1])
} else {
result=context.fn()
}
delete context.fn
return result
}
var clickApply=function(a,b){
console.log('我是apply', this, a, b)
}
let a={
name: '我是陈皮'
}
clickApply.myApply(a,['chen','peng'])
Function.prototype.myApply=function(context){
let context=context||window;
context.fn=this;
if(arguments[1]){
let result=context.fn(...arguments[1])
}else {
let result=context.fn()
}
delete context.fn
return result
}
</script>
</body>
</html>