Skip to content

Proposal: New keyword for Mixins #7798

Closed
@ivan-pro

Description

@ivan-pro

Following the mixin sample from here, I propose a new keyword for implementing mixins. The goal is to keep the code as clean as possible by letting the compiler know that applyMixins has to be included in the codebase and it must be called. Let's say the keyword is 'mixin', the aforementioned example would then be brought down to

class SmartObject mixin Disposable, Activatable {
    constructor() {
        setInterval(() => console.log(this.isActive + " : " + this.isDisposed), 500);
    }

    interact() {
        this.activate();
    }
}

An alternative way to declare it in order to avoid confusion with implements/extends:

class SmartObject {
    mixin Disposable
    mixin Activatable 

    constructor() {
        setInterval(() => console.log(this.isActive + " : " + this.isDisposed), 500);
    }

    interact() {
        this.activate();
    }
}

The compiler would then add the applyMixins function and call it as shown in the article.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions