forked from CommanderXL/xRoute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
request-handler.js
72 lines (52 loc) · 1.35 KB
/
request-handler.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class RequestHandler {
constructor() {
}
}
class MethodA extends RequestHandler {
}
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
this.toString();
}
test() {
const a = new Test(this);
console.log(Function.prototype.toString.call(a));
}
toString() {
}
}
class ClassPoint extends Point {
toString() {
console.log(123);
}
}
//es6中子类继承父类时,会自动调用父类的构造函数
//即在定义es6子类时,就算没有写constructor也会默认执行
/**
* class ClassPoint extends Point {
* constructor(...args) {
* super(...args);
* }
* }
*/
var point = new ClassPoint();
Function.prototype.bind = function() {
let self = this, //保存原函数
context = [].shift.call(arguments),
args = [].slice.call(arguments);
return () => {
return self.apply(context, [].concat.call(args, [].slice.call(arguments)));
//执行新的函数,把之前传入的context当做新函数体内的this
//并且组合两次分别传入的参啊,作为新函数的参数
}
}
var obj = {
name: 'sven'
}
var func = function(a, b, c, d) {
alert(this.name); //输出 sven
alert([a, b, c, d]); //输出[1, 2, 3, 4]
}.bind(obj, 1, 2);
func(3, 4);