Object method shorthand after initial declaration

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Object method shorthand after initial declaration

Brian Blakely
Extend the method shorthand syntax beyond initial object declaration.

```js
const obj = {};

obj.foo() {...}
```

Equivalent 2015 syntax:

```js
const obj = {
  foo() {...}
};
```

This is nice for assignment to context:

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

const foo = new Foo();
foo.bar();
foo.baz();
```

Equivalent 2015 syntax:

```js
function Foo() {
  this.bar = function() {...};
  this.baz = function() {...};
}
```

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Object method shorthand after initial declaration

James Kyle
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;
}


On Wed, 25 Oct 2017 at 4:29 am, Brian Blakely <[hidden email]> wrote:
Extend the method shorthand syntax beyond initial object declaration.

```js
const obj = {};

obj.foo() {...}
```

Equivalent 2015 syntax:

```js
const obj = {
  foo() {...}
};
```

This is nice for assignment to context:

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

const foo = new Foo();
foo.bar();
foo.baz();
```

Equivalent 2015 syntax:

```js
function Foo() {
  this.bar = function() {...};
  this.baz = function() {...};
}
```
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Object method shorthand after initial declaration

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

On Tue, Oct 24, 2017 at 2:41 PM, James Kyle <[hidden email]> wrote:
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;
}


On Wed, 25 Oct 2017 at 4:29 am, Brian Blakely <[hidden email]> wrote:
Extend the method shorthand syntax beyond initial object declaration.

```js
const obj = {};

obj.foo() {...}
```

Equivalent 2015 syntax:

```js
const obj = {
  foo() {...}
};
```

This is nice for assignment to context:

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

const foo = new Foo();
foo.bar();
foo.baz();
```

Equivalent 2015 syntax:

```js
function Foo() {
  this.bar = function() {...};
  this.baz = function() {...};
}
```
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Object method shorthand after initial declaration

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


On Tue, Oct 24, 2017 at 12:45 PM, Brian Blakely
<[hidden email]> wrote:

> Is it only valid with a semicolon after `foo()`, though?  Pragma without
> semicolon throws in three engines.
>
> On Tue, Oct 24, 2017 at 2:41 PM, James Kyle <[hidden email]> wrote:
>>
>> 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;
>> }
>>
>>
>> On Wed, 25 Oct 2017 at 4:29 am, Brian Blakely <[hidden email]>
>> wrote:
>>>
>>> Extend the method shorthand syntax beyond initial object declaration.
>>>
>>> ```js
>>> const obj = {};
>>>
>>> obj.foo() {...}
>>> ```
>>>
>>> Equivalent 2015 syntax:
>>>
>>> ```js
>>> const obj = {
>>>   foo() {...}
>>> };
>>> ```
>>>
>>> This is nice for assignment to context:
>>>
>>> ```js
>>> function Foo() {
>>>   this.bar() {...}
>>>   this.baz() {...}
>>> }
>>>
>>> const foo = new Foo();
>>> foo.bar();
>>> foo.baz();
>>> ```
>>>
>>> Equivalent 2015 syntax:
>>>
>>> ```js
>>> function Foo() {
>>>   this.bar = function() {...};
>>>   this.baz = function() {...};
>>> }
>>> ```
>>> _______________________________________________
>>> es-discuss mailing list
>>> [hidden email]
>>> https://mail.mozilla.org/listinfo/es-discuss
>
>
>
> _______________________________________________
> es-discuss mailing list
> [hidden email]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Object method shorthand after initial declaration

Jordan Harband
The following style (although not one I prefer) would have to also work as a function definition:
```
obj.foo()
{
}
```

On Tue, Oct 24, 2017 at 1:41 PM, /#!/JoePea <[hidden email]> wrote:
`obj.foo() {}` is a syntax error in Chrome, so it seems possible to
make that a function definition.
/#!/JoePea


On Tue, Oct 24, 2017 at 12:45 PM, Brian Blakely
<[hidden email]> wrote:
> Is it only valid with a semicolon after `foo()`, though?  Pragma without
> semicolon throws in three engines.
>
> On Tue, Oct 24, 2017 at 2:41 PM, James Kyle <[hidden email]> wrote:
>>
>> 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;
>> }
>>
>>
>> On Wed, 25 Oct 2017 at 4:29 am, Brian Blakely <[hidden email]>
>> wrote:
>>>
>>> Extend the method shorthand syntax beyond initial object declaration.
>>>
>>> ```js
>>> const obj = {};
>>>
>>> obj.foo() {...}
>>> ```
>>>
>>> Equivalent 2015 syntax:
>>>
>>> ```js
>>> const obj = {
>>>   foo() {...}
>>> };
>>> ```
>>>
>>> This is nice for assignment to context:
>>>
>>> ```js
>>> function Foo() {
>>>   this.bar() {...}
>>>   this.baz() {...}
>>> }
>>>
>>> const foo = new Foo();
>>> foo.bar();
>>> foo.baz();
>>> ```
>>>
>>> Equivalent 2015 syntax:
>>>
>>> ```js
>>> function Foo() {
>>>   this.bar = function() {...};
>>>   this.baz = function() {...};
>>> }
>>> ```
>>> _______________________________________________
>>> es-discuss mailing list
>>> [hidden email]
>>> https://mail.mozilla.org/listinfo/es-discuss
>
>
>
> _______________________________________________
> es-discuss mailing list
> [hidden email]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss