File tree Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -92,19 +92,21 @@ lead to bugs.
92
92
In order to create a new object, one should rather use a factory and construct a
93
93
new object inside of that factory.
94
94
95
- function Foo () {
96
- var obj = {};
97
- obj.value = 'blub ';
95
+ function CarFactory () {
96
+ var car = {};
97
+ car.owner = 'nobody ';
98
98
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;
102
103
}
103
104
104
- obj.getPrivate = function() {
105
- return private ;
105
+ car.getMPG = function() {
106
+ return milesPerGallon ;
106
107
}
107
- return obj;
108
+
109
+ return car;
108
110
}
109
111
110
112
While the above is robust against a missing ` new ` keyword and certainly makes
You can’t perform that action at this time.
0 commit comments