-
Notifications
You must be signed in to change notification settings - Fork 11
Remove redundant class in 3-class.js example
#5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove redundant class in 3-class.js example
#5
Conversation
| 'use strict'; | ||
|
|
||
| const logable = (fields) => | ||
| class Logable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shows class-returning function, rewriting will hide the essence of the example
| }, | ||
| }); | ||
| const logable = fieldRules => data => { | ||
| var result = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why var?
| var result = {} | |
| const result = {}; |
| const p1 = new Person({ name: 'Marcus Aurelius', born: 121 }); | ||
| const p1 = Person({ name: 'Marcus Aurelius', born: 121 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use UpperCamel for classes and lowerCamep for functions, methods
| }); | ||
| const logable = fieldRules => data => { | ||
| var result = {} | ||
| Object.keys(fieldRules).forEach(key => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keys/forEach will create array and make more function calls
| }) | ||
| result.toString = () => | ||
| `Logable\t${ | ||
| Object.keys(fieldRules).map(key => data[key] + '\t').join() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not ok to access data[key] from map, because data is out of mapping function scope, it will work but semantics does not fit
No description provided.