JS补记
两种实现继承的方式
-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20function Car() {
var self = this;
self.type = "Car"
self.go = function() {
console.log("Going...");
};
};
Toyota = function() {};
Toyota.prototype = new Car();
Toyota.prototype.constructor = function() {
var self = this;
self.type = "Toyota";
self.go = function() {
console.log("A Toyota car is going...");
}
};
Toyota.prototype.isJapaneseCar = true;
var t = new Toyota();
console.log(t instanceof Toyota);
console.log(t instanceof Car); -
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17var Car = Class.create({
initialize: function() {
this.type = "Car";
},
go: function() {
console.log("Going...");
}
});
var Toyota = Class.create(Car, {
initialize: function() {
this.type = "Toyota";
this.isJapaneseCar = true;
},
go: function() {
console.log("A Toyota car is going...");
}
});- 关于父类调用
1
2
3
4
5
6
7
8
9
10var Toyota = Class.create(Car, {
initialize: function() {
this.type = "Toyota";
this.isJapaneseCar = true;
},
go: function($super) {
$super();
console.log("A Toyota car is going...");
}
});
- 关于父类调用
选择器
链表实现
1 | var Node = Class.create({ |