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
Structures.extend doesn't search the prototype chain #3215
Comments
Another example that doesn't use mixins: module.exports = Structures.extend("Guild", Guild => {
class CoolGuild extends Guild {}
class CoolerGuild extends CoolGuild {}
return CoolerGuild;
}); Even though CoolerGuild extends Guild (indirectly), Structures.extend will return an error. Using instanceof fixes this. |
Dragoteryx
changed the title
Structures.extend is not compatible with mixins
Structures.extend doesn't search the prototype chain
Apr 17, 2019
I don't see a problem with your proposed solution, however, I am confused on why this is an issue instead of a pr since you are proposing a solution? |
Oh yeah, you're right. Just realised that lol. Going to make a push request. |
5 tasks
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Is your feature request related to a problem? Please describe.
I started to work on my own Discord.js framework, and I created a mix-in called CommandManager.
So this is what my Guild extender looks like:
Simple enough, this creates a new class called GungnirGuild, which inherits properties from CommandManager, which inherits properties from Guild. Except the check inside the extend function throws an Error, because it checks for the prototype of the returned class and doesn't check its prototype chain.
Describe the ideal solution
Use instanceof instead of directly comparing the prototypes.
Replace this:
with this:
This will check if the extended class is in the prototype chain, and will work even if the returned class doesn't directly inherit from the extended class.
Describe alternatives you've considered
Defining my command related functions/properties on every class I want them to be available, but that would take a while and is an anti-pattern.
The text was updated successfully, but these errors were encountered: