1ObjMaker = function() {this.a = 'first';};
2// ObjMaker is just a function, there's nothing special about it that makes
3// it a constructor.
4
5ObjMaker.prototype.b = 'second';
6// like all functions, ObjMaker has an accessible prototype property that
7// we can alter. I just added a property called 'b' to it. Like
8// all objects, ObjMaker also has an inaccessible [[prototype]] property
9// that we can't do anything with
10
11obj1 = new ObjMaker();
12// 3 things just happened.
13// A new, empty object was created called obj1. At first obj1 was the same
14// as {}. The [[prototype]] property of obj1 was then set to the current
15// object value of the ObjMaker.prototype (if ObjMaker.prototype is later
16// assigned a new object value, obj1's [[prototype]] will not change, but you
17// can alter the properties of ObjMaker.prototype to add to both the
18// prototype and [[prototype]]). The ObjMaker function was executed, with
19// obj1 in place of this... so obj1.a was set to 'first'.
20
21obj1.a;
22// returns 'first'
23obj1.b;
24// obj1 doesn't have a property called 'b', so JavaScript checks
25// its [[prototype]]. Its [[prototype]] is the same as ObjMaker.prototype
26// ObjMaker.prototype has a property called 'b' with value 'second'
27// returns 'second'
1function Car(make, model, year) {
2 this.make = make;
3 this.model = model;
4 this.year = year;
5}
6//create a object with three keys, make, model, and year
7
8var myCar = new Car('Eagle', 'Talon TSi', 1993);
9// use the new operator to create any number of car objects with this template object Car above
10