-
Notifications
You must be signed in to change notification settings - Fork 0
/
oop.js
113 lines (93 loc) · 2.47 KB
/
oop.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
Vehicle = (function() {
// console.log("DECLARING Vehicle");
var $this = function (options) {
console.log("Construct Vehicle");
this.defaultOptions(options, {
hasEngine: false,
hasWheels: false,
});
};
EasyOOP.extend(null, $this, {
show: function() {
console.log(this.hasEngine + ", " + this.hasWheels);
}
});
return $this;
})();
//var myVehicle = new Vehicle({hasEngine: false, hasWheels: true});
//var base = myVehicle.base();
// console.log(base);
// myVehicle.base().show(1,2);
Car = (function() {
// console.log("DECLARING Car");
$this = function(options) {
console.log("Construct Car");
// $parent.prototype.constructor.call(this, {hasEngine: true, hasWheels: true});
this.parent().constructor({hasEngine: true, hasWheels: true});
this.defaultOptions(options, {
make: '',
model: '',
hp: 0,
});
},
EasyOOP.extend(Vehicle, $this, {
show: function() {
// $parent.prototype.show.call(this);
this.parent().show();
console.log(this.make + ", " + this.model + ", " + this.hp);
}
});
return $this;
})();
myBMW = new Car({make: 'BMW', model: '320i', hp: 160});
myBMW.show();
myBMW.parent().show();
/*
console.log("NEW BASE");
var mybase = myBMW.base();
// console.log(mybase);
console.log("SHOW");
mybase.show();
mybase.mtf();
*/
// console.log(myBMW.baseObject);
//myBMW.show();
// myBMW.base().show();
// console.log(myBMW.basePrototype);
// myBMW.base.show();
/*
Audi = (function() {
var $parent = Car;
// console.log("DECLARING Audi");
$this = function(options) {
console.log("Construct Audi");
$parent.prototype.constructor.call(this, {make: "Audi", model: options.model, hp: options.hp});
// this.base.constructor({make: "Audi", model: options.model, hp: options.hp});
this.defaultOptions(options, {
color: 'blue',
});
},
EasyOOP.extend(Car, $this, {
show: function() {
$parent.prototype.show.call(this);
console.log(this);
// this.base.show();
console.log(this.color);
}
});
return $this;
})();
// console.log(Car.prototype);
myBMW = new Car({make: 'BMW', model: '320i', hp: 160});
myBMW.show();
myAudi = new Audi({model: 'A4', hp: 160, color: 'red'});
myAudi.show();
// console.log(myAudi.model);
*/
/*
var myCar = new Vehicle({hasWheels: true, hasEngine: true});
console.log(myCar instanceof Vehicle);
console.log(myCar instanceof testBase);
console.log(myCar instanceof testNonBase);
myCar.show();
*/