FAQ Database Discussion Community


ECMAScript6 arrow function that returns an object

javascript,ecmascript-6,arrow-functions
When returning an object from an arrow function, it seems that it is necessary to use an extra set of {} and a return statement because of an ambiguity in the grammar: p => { return { foo: 'bar' } } If the arrow function returns anything else, the {}...

Arrow functions not working in node --harmony under Ubuntu

node.js,ecmascript-harmony,arrow-functions
I'm trying to use arrow functions in node v0.10.33 under Ubuntu 14.04 (I'm running node with --harmony flag), but I'm getting this error: console.log( [1,2,3,4].map(x => x*x) ); ^ SyntaxError: Unexpected token > at Module._compile (module.js:439:25) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup...

Arrow Functions and This

javascript,this,ecmascript-6,arrow-functions
I'm trying out ES6 and want to include a property inside my function like so var person = { name: "jason", shout: () => console.log("my name is ", this.name) } person.shout() // Should print out my name is jason However, when I run this code console only logs my name...

What does arrow function '() => {}' mean in Javascript? [duplicate]

javascript,ecmascript-6,arrow-functions
This question already has an answer here: What's the meaning of “=>” in JavaScript? 5 answers I was reading the source for ScrollListView and in several places I see the use of () => {}. Such as on line 25, this.cellReorderThreshold = () => { var ratio = (this.CELLHEIGHT*this.cellsWithinViewportCount)/4;...

Using ES6 Arrow Functions in Node 0.11 w/ Foo.prototype

javascript,node.js,ecmascript-6,ecmascript-harmony,arrow-functions
I'm getting what I see as unexpected behavior in using arrow functions inside a prototype extension. function ES6Example(){} ES6Example.prototype.foo = function(bar){ return ((baz) => { console.log(this) this.bar = baz })(bar) } var es6Example = new ES6Example es6Example.foo('qux') console.info(es6Example.bar) The above code results in the global context being printed out, as...