Thursday, July 14, 2016

Javascript is weirder than Perl

Found something weird in here a Javascript object/associative array declared without keys. First I thought it might be a fat-comma-is-just-a-comma situation like in Perl, but there were three elements between { and }. So I investigated.

If you thought that in Perl there are too many ways to do it, run this with ES6 enabled:

const bla = () => { console.log("ran bla") };
const gar = () => { console.log("ran gar") };
function asdf () {
    console.log("ran asdf");

const xxx = { bla, gar, asdf };


for the impatient, this is the output
{ bla: [Function], gar: [Function], asdf: [Function: asdf] }

I did not expect that.

No comments:

Post a Comment