-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Functions are cleaner than subclasses #116
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
Conversation
Agree with this due to the ability to create array literals. Arrays created by JSON.parse() also wouldn't get the new functionality. Should the function name be diffArray() to express that specifically works with arrays? |
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.
Hey David! Thank you for contributing your expertise. I've left some comments.
@@ -609,6 +609,35 @@ class SuperArray extends Array { | |||
``` | |||
**[⬆ back to top](#table-of-contents)** | |||
|
|||
### Functions are often cleaner than subclasses ### |
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.
Does this replace the SuperArray
example?
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.
I would instead recommend a rewrite of the SuperArray example. Will update this PR with rewitten section.
|
||
A class will limit the usage of the diff feature to the subclass only. A better option is to write a stateless function, that accept two arrays and calculate the difference between them. | ||
|
||
```javascript |
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 doesn't keep with the format of Bad/Good.
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.
Fixed!
Thank you for the feedback @ryanmcdermott! I will update the pull request. |
In this updated PR, I have added a new section using the Bad/Good format. |
@DavidVujic Sorry, the original code was changed in #124. |
Great @vsemozhetbyt! I saw the changes, very nice improvement. |
Thank you) I mean, maybe it would be good for consistency to update these fragments in your examples as well. |
Done! Now hoping for a merge and/or more feedback for improvement. |
I think this is a really great idea for an addition! The only issue I have is that |
Thank you for the feedback @ryanmcdermott! I have given it some thought and think the "good" part of the SuperArray example should be a stateless function, because of some drawbacks that I think are major:
Let me know what you think! If you don't like it, please tell me and I will close the pull request. (I have updated the pull request. It is updated with a function as "good" instead of the class.) |
Hey David! Thanks for spending time revising this. I want to combine this PR with another: #139 The motivation is that I think we should say something about the nature of classes in the preamble of the Classes section. We can incorporate your thoughts into that introduction. I want to leave this example the way it is for now! If you have time would love to see your work as an intro in the Classes section! |
A drawback with a class extending the Array global, is that you are required to instantiate it using the 'new' keyword. Also, the 'diff' feature is limited to the subclass only.