Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #28549 > unrolled thread

function in hash

Started byStone Zhong <stone.zhong@gmail.com>
First post2015-08-20 23:20 -0700
Last post2015-08-21 07:41 -0700
Articles 4 — 2 participants

Back to article view | Back to comp.lang.javascript


Contents

  function in hash Stone Zhong <stone.zhong@gmail.com> - 2015-08-20 23:20 -0700
    Re: function in hash Stone Zhong <stone.zhong@gmail.com> - 2015-08-20 23:21 -0700
      Re: function in hash Andreas Bergmaier <andber93@web.de> - 2015-08-21 11:39 +0200
        Re: function in hash Stone Zhong <stone.zhong@gmail.com> - 2015-08-21 07:41 -0700

#28549 — function in hash

FromStone Zhong <stone.zhong@gmail.com>
Date2015-08-20 23:20 -0700
Subjectfunction in hash
Message-ID<259c4391-a79d-43c9-b4f4-d6b3896ab9e3@googlegroups.com>
Hi there,

I wrote some code below (Format A) by mistake:

Format A:
------------------
var a = {
  x: 1,
  y: 2,
  foo() {
    alert("foo");
  },
};

Actually I intend to write (Format B):

Format B:
------------------
var a = {
  x: 1,
  y: 2,
  foo: function() {
    alert("foo");
  },
};

However, to my surprise, Format A works well in Firefox 38.2.0, I haven't tried other browser, am I missing anything? I thought Format A's syntax is wrong.

Thanks,
Stone

[toc] | [next] | [standalone]


#28550

FromStone Zhong <stone.zhong@gmail.com>
Date2015-08-20 23:21 -0700
Message-ID<b458a4bb-90fb-43ef-96fb-2806bec85a23@googlegroups.com>
In reply to#28549
On Thursday, August 20, 2015 at 11:20:26 PM UTC-7, Stone Zhong wrote:
> Hi there,
> 
> I wrote some code below (Format A) by mistake:
> 
> Format A:
> ------------------
> var a = {
>   x: 1,
>   y: 2,
>   foo() {
>     alert("foo");
>   },
> };
> 
> Actually I intend to write (Format B):
> 
> Format B:
> ------------------
> var a = {
>   x: 1,
>   y: 2,
>   foo: function() {
>     alert("foo");
>   },
> };
> 
> However, to my surprise, Format A works well in Firefox 38.2.0, I haven't tried other browser, am I missing anything? I thought Format A's syntax is wrong.
> 
> Thanks,
> Stone

Another ES5 black magic?

[toc] | [prev] | [next] | [standalone]


#28551

FromAndreas Bergmaier <andber93@web.de>
Date2015-08-21 11:39 +0200
Message-ID<mr6rjc$dbi$1@news.albasani.net>
In reply to#28550
Stone Zhong schrieb:

>> I wrote some code below (Format A) by mistake:
>>
>> var a = {
>>    x: 1,
>>    y: 2,
>>    foo() {
>>      alert("foo");
>>    },
>> };
>>
>> to my surprise, this works well in Firefox 38.2.0, I haven't tried other browser, am I missing anything?
>
> Another ES5 black magic?

Nope, ES6 magic. It's called a method definition: 
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions

  Bergi

[toc] | [prev] | [next] | [standalone]


#28552

FromStone Zhong <stone.zhong@gmail.com>
Date2015-08-21 07:41 -0700
Message-ID<ce68f784-976f-4299-91c0-a6e125051166@googlegroups.com>
In reply to#28551
On Friday, August 21, 2015 at 2:39:03 AM UTC-7, Andreas Bergmaier wrote:
> Stone Zhong schrieb:
> 
> >> I wrote some code below (Format A) by mistake:
> >>
> >> var a = {
> >>    x: 1,
> >>    y: 2,
> >>    foo() {
> >>      alert("foo");
> >>    },
> >> };
> >>
> >> to my surprise, this works well in Firefox 38.2.0, I haven't tried other browser, am I missing anything?
> >
> > Another ES5 black magic?
> 
> Nope, ES6 magic. It's called a method definition: 
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Method_definitions
> 
>   Bergi

Thanks Bergi, it seems this feature is good!

- Stone

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web