Minimalist Classes

Matthew Tretter matthewtretter at gmail.com
Thu Nov 3 06:53:39 PDT 2011


Sorry, I'll try to be more clear.

What's "super-intuitive" isn't *that* you use the form "class name expr", it's how you interact with that form once you know what it does.  The reason is self-evident—people know how to work with object literals and functions.  This is not true of the Leather form which, like I said, would probably inspire a lot of "run(a){…}" attempts at function definitions in non-class contexts. Not that that alone is enough to disqualify it, but it's something that should be taken into consideration.

Off the top of my head, one use-case would be Python-like method decorators:

    class Runner {
        run: require_auth(function(a) {
        })
    }

Another would be the dynamic definition of methods:

    class Runner {
        run: (function() {
            return someFeatureIsSupported ? feature : polyfill;
        })()
    }

There are many more, I'm sure, but the point is this: a syntax that makes use of the elements already in the language (instead of providing alternates) is going to be more familiar and therefore objectively more intuitive. Yes, the class keyword brings some new wrinkles, but that will be true of any proposal.


More information about the es-discuss mailing list