Giter Club home page Giter Club logo

Comments (6)

tech6hutch avatar tech6hutch commented on June 25, 2024

I think I like this idea. It's better than the this._patch internal method someone suggested, that reversed it by removing the ...args from the constructor.

from klasa.

tech6hutch avatar tech6hutch commented on June 25, 2024

Actually, have you...tested this? I'm not sure you can use methods from child classes.

from klasa.

PierreAndreis avatar PierreAndreis commented on June 25, 2024

@tech6hutch I have tested, and yes they are able to
https://jsbin.com/migiqinafe/edit?js,console

from klasa.

bdistin avatar bdistin commented on June 25, 2024

This is a terrible practice (limits the namespace of the class, just to store the same data on the class again later, and that's not even counting any resolved state such as usage. So the data is tripled via instance.config(), instance._internalConfig, and instance.things. As well as there are times you want to add your own state to your class instances, for which that should always be done in the constructor anyway, else you make V8 choke an re-compile your instances every time you add properties.)

Not that you can't do this in your own bot (extend Command or w/e to give yourself this way of setting config)... But this isn't something that will be done in the core framework.

from klasa.

PierreAndreis avatar PierreAndreis commented on June 25, 2024

@bdistin What my proposal was in reality is to eliminate the need of extending args when the user is not going to do anything with it.

config method doesn't need to be a function, it can be just a simple object. This is how React handles their classes. I don't see bad practice in this compared forcing the user to be aware of arguments on constructor that their don't need to.

you make V8 choke an re-compile your instances every time you add properties.

I don't see how you would add properties to the class in runtime (?)

limits the namespace of the class, just to store the same data on the class again later, and that's not even counting any resolved state such as usage. So the data is tripled via instance.config(), instance._internalConfig, and instance.things. As well as there are times you want to add your own state to your class instances, for which that should always be done in the constructor anyway, else you make V8 choke an re-compile your instances every time you add properties.

Again, my demo was an example on what we may do. We can literally force config to be an object and mention it directly.
The bigger picture is that the user doesn't need to be aware of the constructor if he is not responsible for it

from klasa.

bdistin avatar bdistin commented on June 25, 2024

That sentence is meant to be taken as a whole. As in, if you eliminate using constructor, when people want to add properties, they may be tempted to add them in any method, rather than in the constructor which really isn't as optional as it may appear to be.

from klasa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.