Object method shorthand after initial declaration

# Brian Blakely (a year ago)

Extend the method shorthand syntax beyond initial object declaration.

const obj = {};

obj.foo() {...}

Equivalent 2015 syntax:

const obj = {
  foo() {...}

This is nice for assignment to context:

function Foo() {
  this.bar() {...}
  this.baz() {...}

const foo = new Foo();

Equivalent 2015 syntax:

function Foo() {
  this.bar = function() {...};
  this.baz = function() {...};
# James Kyle (a year ago)

To parse it that way would be changing behavior.

obj.foo() {} this.bar() {}

Are both call expressions followed by a block. They are valid syntaxes today.


obj.foo(); { let a = 1; }

# Brian Blakely (a year ago)

Is it only valid with a semicolon after foo(), though? Pragma without semicolon throws in three engines.

# /#!/JoePea (a year ago)

obj.foo() {} is a syntax error in Chrome, so it seems possible to make that a function definition. /#!/JoePea

# Jordan Harband (a year ago)

The following style (although not one I prefer) would have to also work as a function definition: