Skip to content

Commit f5bd48b

Browse files
author
Chris Anderson
committed
change factory example to use cars instead of obj
1 parent 4315284 commit f5bd48b

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

doc/en/function/constructors.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,21 @@ lead to bugs.
9292
In order to create a new object, one should rather use a factory and construct a
9393
new object inside of that factory.
9494

95-
function Foo() {
96-
var obj = {};
97-
obj.value = 'blub';
95+
function CarFactory() {
96+
var car = {};
97+
car.owner = 'nobody';
9898

99-
var private = 2;
100-
obj.someMethod = function(value) {
101-
this.value = value;
99+
var milesPerGallon = 2;
100+
101+
car.setOwner = function(newOwner) {
102+
this.owner = newOwner;
102103
}
103104

104-
obj.getPrivate = function() {
105-
return private;
105+
car.getMPG = function() {
106+
return milesPerGallon;
106107
}
107-
return obj;
108+
109+
return car;
108110
}
109111

110112
While the above is robust against a missing `new` keyword and certainly makes

0 commit comments

Comments
 (0)