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

Deprecate @traits decorator #3

Open
Nashorn opened this issue Sep 20, 2020 · 3 comments
Open

Deprecate @traits decorator #3

Nashorn opened this issue Sep 20, 2020 · 3 comments
Assignees

Comments

@Nashorn
Copy link
Collaborator

Nashorn commented Sep 20, 2020

@traits() is deprecated in favor of .with().
The @traits decorator can only run after a class is defined and will overwrite methods defined in the class in place, modifying the Class prototype and won't allow super() calls.

New Syntax:

//---------------------native class-based traits-----------------
class TraitX {
    foo(){
        alert("foo X")
    }
}

class TraitZ {
    zee(){
        alert("zee")
    }
}

//---------------------classes that mix in traits-----------------

class Y {
    constructor(){
        alert("cctor of Y")
    }
    bar(){
        alert("bar")
    }
}

class T extends Y.with(TraitX,TraitZ) {
    constructor(){
        super();
        this.foo()
    }

    foo(){
        alert("foo T");
        super.foo();//from TraitX
        this.bar()//from Y
        this.zee()//from TraitZ
    }    
}
@Nashorn Nashorn added the bug Something isn't working label Sep 20, 2020
@Nashorn Nashorn self-assigned this Sep 21, 2020
@Nashorn
Copy link
Collaborator Author

Nashorn commented Sep 25, 2020

The above is valid JavaScript. And will stay supported.

NEW PROPOSAL

As an added enhancement, modify transpiler to interpret the following cleaner syntax:

class T extends Y with TraitX, TraitZ {
    constructor(){
        super();
        this.foo()
    }

    foo(){
        alert("foo T");
        super.foo();//from TraitX
        this.bar()//from Y
        this.zee()//from TraitZ
    }    
}

@Nashorn Nashorn added the syntax label Sep 25, 2020
@Nashorn
Copy link
Collaborator Author

Nashorn commented Dec 19, 2020

Traits deprecated message added.

@Nashorn
Copy link
Collaborator Author

Nashorn commented Apr 13, 2021

Runtime js parsable method supported:
class T extends Y.with(TraitX,TraitZ) { }

@Nashorn Nashorn added deprecated and removed bug Something isn't working syntax labels Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant