Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What is the syntax used in the third example of "This in an object method"? I have never seen it, looks like an error to me.


It’s using object shorthand.

Rather than:

    {foo: foo, bar: function(){}}
You can just do:

    {foo, bar(){}}


It's new syntactic sugar for declaring object literals. Google "es6 object literals".


When you say "looks like an error", did you try running it? I assume you have a web browser handy.

All the examples in that section both look correct to me, and run as I'd expect in the JS environment I have closest-to-hand.

If you want help on the syntax, you should pose a more-specific question. Exactly what code looks like an error, and why do you think it's an error, and so on?


Sorry, I was on mobile and could not run it in the browser console. It was an honest question, but I already got the answer.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: