File tree 1 file changed +53
-0
lines changed
1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -243,6 +243,59 @@ function loadPages(count: number = 10) {
243
243
244
244
** [ ⬆ back to top] ( #table-of-contents ) **
245
245
246
+ ### Use enum to document the intent
247
+
248
+ Enums can help you document the intent of the code. For example when we are concerned about values being
249
+ different rather than the exact value of those.
250
+
251
+ ** Bad:**
252
+
253
+ ``` ts
254
+ const GENRE = {
255
+ ROMANTIC: ' romantic' ,
256
+ DRAMA: ' drama' ,
257
+ COMEDY: ' comedy' ,
258
+ DOCUMENTARY: ' documentary' ,
259
+ }
260
+
261
+ projector .configureFilm (GENRE .COMEDY );
262
+
263
+ class Projector {
264
+ // delactation of Projector
265
+ configureFilm(genre ) {
266
+ switch (genre ) {
267
+ case GENRE .ROMANTIC :
268
+ // some logic to be executed
269
+ }
270
+ }
271
+ }
272
+ ```
273
+
274
+ ** Good:**
275
+
276
+ ``` ts
277
+ enum GENRE {
278
+ ROMANTIC ,
279
+ DRAMA ,
280
+ COMEDY ,
281
+ DOCUMENTARY ,
282
+ }
283
+
284
+ projector .configureFilm (GENRE .COMEDY );
285
+
286
+ class Projector {
287
+ // delactation of Projector
288
+ configureFilm(genre ) {
289
+ switch (genre ) {
290
+ case GENRE .ROMANTIC :
291
+ // some logic to be executed
292
+ }
293
+ }
294
+ }
295
+ ```
296
+
297
+ ** [ ⬆ back to top] ( #table-of-contents ) **
298
+
246
299
## Functions
247
300
248
301
### Function arguments (2 or fewer ideally)
You can’t perform that action at this time.
0 commit comments