Keywords as method names

David Herman dherman at
Wed Aug 21 17:19:51 PDT 2013

In Lisp it makes sense to allow binding keywords because there's no such thing as a keyword: once you bind it, it's a variable and you can refer to it. In JS it's impossible to refer to it as a variable so it's just an (un)attractive nuisance.

The only place where I could see this being arguably useful in ES6 is:

    // foo.js
    export function function() { }

    // main.js
    module foo from "foo";


But that's still probably not advisable, since it means you can't import the name:

    import { function } from "foo";
    // d'oh

So I don't see any reason why a person shouldn't just use rebinding for that use case:

    // foo.js
    function function_() { }

    export { function_ as function };

To wit: I say leave it out.


On Aug 21, 2013, at 4:13 PM, Jason Orendorff <jason.orendorff at> wrote:

> The ES6 draft says:
>    MethodDefinition : PropertyName ( StrictFormalParameters ) { FunctionBody }
>    PropertyName : IdentifierName
> This means a method name can be a keyword: `obj = {if() {}}`. This is
> consistent with other property names (`{if: true}` is allowed), but
> inconsistent with other function names (`function if(){}` is not
> allowed).
> Why not allow keywords as function names, too?
> -j
> _______________________________________________
> es-discuss mailing list
> es-discuss at

More information about the es-discuss mailing list