[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

function in hash

Stone Zhong

8/21/2015 6:20:00 AM

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
3 Answers

Stone Zhong

8/21/2015 6:22:00 AM

0

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?

Andreas Bergmaier

8/21/2015 9:39:00 AM

0

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_d...

Bergi

Stone Zhong

8/21/2015 2:42:00 PM

0

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_d...
>
> Bergi

Thanks Bergi, it seems this feature is good!

- Stone