-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconstructor_functions.js
67 lines (57 loc) · 1.29 KB
/
constructor_functions.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
var x = 10;
var engine=function(c,m,e){
this.capcity=c;
this.model=m;
this.expiryDate=e;
}
// variable declarations to function
var Car = function (model,e, color, year, isOn) {
this.Engine=e;
var x = 20;
this.xyz = 10;
//public
this.model = model;
this.color = color;
this.isOn = isOn;
//private
var Model = "private";
function swithOnEngine(){
return 1+2;
}
this.getModel=function(){
return Model;
}
this.setModel=function(m){
console.log(Model);
Model=m;
return Model;
}
this.isSwitchedOn = function () {
this.isOn = true;
return this.isOn;
}
// fields private
}
var x=new Car(20);
//initialize engine
x.Engine={capcity:3000,expiryDate:'1/1/2019'};
console.log(x.Engine);
x.Engine={capcity:3000,expiryDate:'1/1/2019'};
x.Engine=new engine('3000','toyota','');
x.Engine.capcity
console.log(x.Model);
x.model=20;
x.Car.Model=
console.log(x.Model);
//console.log(Car());
var bmwCar = new Car('bmw', 'red');
bmwCar.abc = 10;
///console.log(bmwCar.color);
var mercededCar = new Car('mercedes');
Car.prototype.expiryDate = "1-1-2000";
var myCar = new Car();
myCar.expiryDate = "1-1-2012";
bmwCar = myCar;
console.log(myCar.expiryDate);
// the same as :
console.log(bmwCar.expiryDate);