-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbind.html
More file actions
27 lines (25 loc) · 724 Bytes
/
bind.html
File metadata and controls
27 lines (25 loc) · 724 Bytes
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
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<!-- bind()函数的底层模拟实现 -->
<script type="text/javascript">
Function.prototype.newBind = function (target) {
var target = target || window;
var that = this;
var args = [].slice.call(arguments, 1);
var temp = function() {};
var func = function () {
var _args = [].slice.call(arguments, 0);
return that.apply(this instanceof temp ? this : target, args.cancat(_args));
}
temp.prototype = this.prototype;
func.prototype = new temp();
return func;
}
</script>
</body>
</html>