Skip to content
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

ES6 classes #38

Open
brodybits opened this issue Dec 12, 2018 · 1 comment
Open

ES6 classes #38

brodybits opened this issue Dec 12, 2018 · 1 comment

Comments

@brodybits
Copy link

would be better than setting prototype functions, as part of new major release (#20)

I would personally favor a more functional approach, should be possible to make it more functional in a followup stage.

@breautek
Copy link
Contributor

I think an OO approach would better, and I'll explain the rationale:

  • Project appears to be already fairly OO (that is you have a method that returns something an instance of an object, in which you can call methods on)

  • Regardless of the paradigm chosen, holding and managing state will be required (the project data). In a functional approach, this is usually done by either by passing some kind of context object around to functions, or having a function with data encapsulated via a closure, where dynamically allocated methods can have access to (and often return itself so that you can chain methods). I don't really see this very extendable.

    The OO approach, which doesn't need to be complicated, that is I don't think we don't need builders or any other fancy design patterns. We just need a class that can be instantiated to encapsulate the project data and provide methods to manipulate the data, which like a functional approach can be changed by simply returning the instance, if desired.

  • For unit testing purposes, it makes it easier to spy on as the jasmine spyOn feature expects an object, and a string as the member function spy on.

  • If we make a move to TypeScript, (which I would also favour eventually) it's easier to manage a single class type rather than series of function types, and having to expose an internal state type. Every function will still have a type declared naturally when authoring a class signature, but the consuming applications/libraries does not need to explicitly import all of these function types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants