-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs_obj_constructor.js
43 lines (33 loc) · 1.05 KB
/
js_obj_constructor.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
/*
CONSTRUCT JAVASCRIPT OBJECTS WITH FUNCTIONS
We are also able to create objects using constructor functions.
A constructor function is given a capitalized name to make it clear that it is
a constructor.
Here's an example of a constructor function:
var Car = function() {
this.wheels = 4;
this.engines = 1;
this.seats = 1;
};
In a constructor the this variable refers to the new object being created by the
constructor. So when we write,
this.wheels = 4;
inside of the constructor we are giving the new object it creates a property called
wheels with a value of 4.
You can think of a constructor as a description for the object it will create.
Have your MotorBike constructor describe an object with wheels, engines and seats
properties and set them to numbers.
*/
var Car = function() {
this.wheels = 4;
this.engines = 1;
this.seats = 1;
};
// Only change code below this line.
var MotorBike = function() {
this.wheels = 2;
this.engines = 2;
this.seats = 1;
};
var someBike = new MotorBike();
console.log("MotorBike Constructor: ", someBike);