Arc2D icon indicating copy to clipboard operation
Arc2D copied to clipboard

Deprecate @traits decorator

Open Nashorn opened this issue 5 years ago • 3 comments

@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 avatar Sep 20 '20 18:09 Nashorn

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 avatar Sep 25 '20 10:09 Nashorn

Traits deprecated message added.

Nashorn avatar Dec 19 '20 11:12 Nashorn

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

Nashorn avatar Apr 13 '21 10:04 Nashorn