termi / es6-transpiler

Tomorrow's JavaScript syntax today
Other
216 stars 18 forks source link

Sealed classes #59

Open chemerisuk opened 9 years ago

chemerisuk commented 9 years ago

Hi @termi.

Tried to use ES6 syntax for classes and found that the output is not desired in some cases. As far as I understood by default it expects that a class can be inherited therefore adds some extra stuff. But in the real world not all classes need this addition, so I think it will be valuable to have something like below:

class Entry {
    constructor(b) {
        this.b = b;
    }

    toString() {
        return "foo";
    }

    toLocaleString() {
        return "bar";
    }
}

yields

function Entry(b) {
    this.b = b;
};

Entry.prototype = {
    toString: function() {
        return "foo";
    },

    toLocaleString: function() {
        return "bar";
    }
};

Such behavior might be declared using (for example):

/* es6-transpiler class-inheritance:false */

Thoughts?