Object method shorthand after initial declaration

# Brian Blakely (6 years 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();
foo.bar();
foo.baz();

Equivalent 2015 syntax:

function Foo() {
  this.bar = function() {...};
  this.baz = function() {...};
}
# James Kyle (6 years 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.

Think:

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

# Brian Blakely (6 years ago)

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

# /#!/JoePea (6 years ago)

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

# Jordan Harband (6 years ago)

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

obj.foo()
{
}