File tree Expand file tree Collapse file tree 1 file changed +10
-14
lines changed Expand file tree Collapse file tree 1 file changed +10
-14
lines changed Original file line number Diff line number Diff line change @@ -1114,10 +1114,10 @@ and you can chain further class methods onto it.
11141114** Bad:**
11151115``` javascript
11161116class Car {
1117- constructor () {
1118- this .make = ' Honda ' ;
1119- this .model = ' Accord ' ;
1120- this .color = ' white ' ;
1117+ constructor (make , model , color ) {
1118+ this .make = make ;
1119+ this .model = model ;
1120+ this .color = color ;
11211121 }
11221122
11231123 setMake (make ) {
@@ -1137,20 +1137,18 @@ class Car {
11371137 }
11381138}
11391139
1140- const car = new Car ();
1140+ const car = new Car (' Ford ' , ' F-150 ' , ' red ' );
11411141car .setColor (' pink' );
1142- car .setMake (' Ford' );
1143- car .setModel (' F-150' );
11441142car .save ();
11451143```
11461144
11471145** Good:**
11481146``` javascript
11491147class Car {
1150- constructor () {
1151- this .make = ' ' ;
1152- this .model = ' ' ;
1153- this .color = ' ' ;
1148+ constructor (make , model , color ) {
1149+ this .make = make ;
1150+ this .model = model ;
1151+ this .color = color ;
11541152 }
11551153
11561154 setMake (make ) {
@@ -1178,10 +1176,8 @@ class Car {
11781176 }
11791177}
11801178
1181- const car = new Car ()
1179+ const car = new Car (' Ford ' , ' F-150 ' , ' red ' )
11821180 .setColor (' pink' )
1183- .setMake (' Ford' )
1184- .setModel (' F-150' )
11851181 .save ();
11861182```
11871183** [ ⬆ back to top] ( #table-of-contents ) **
You can’t perform that action at this time.
0 commit comments