arrow-functions

Arrow functions not working in node --harmony under Ubuntu

落花浮王杯 提交于 2019-11-30 17:50:02
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 (node.js:119:16) at node.js:906:3 This should work now in node v0.12.x, with the --harmony flag. Also note that you can get arrow functions in node using the babel

Can I use TypeScript overloads when using fat arrow syntax for class methods?

怎甘沉沦 提交于 2019-11-30 17:06:49
I've converted some classes from the conventional form: class TestOverloads { private status = "blah"; public doStuff(selector: JQuery); public doStuff(selector: string); public doStuff(selector: any) { alert(this.status); } } to use arrow function expressions instead: class TestOverloads2 { private status = "blah"; public doStuff = (selector: any) => { alert(this.status); } } so as to avoid scoping problems when the class methods are used in a callback (see here for background). I can't work out how to recreate my overloaded function signatures though. How would I write my overloads when

Typescript: How to call method defined with arrow function in base class using super keyword in child class?

倾然丶 夕夏残阳落幕 提交于 2019-11-30 02:47:16
问题 Given class BaseClass{ count:number=0; public someMethod=():void =>{ this.count++; } } class ChildClass extends BaseClass{ public someMethod=():void=>{ super.someMethod(); //Do more work here. } } I receive the error message: Only public methods of the base class are accessible via the 'super' keyword. @Basarat provides some information here but this seems like a real hack to the language. typescript arrow operator to define a function on prototype How might this be done while preserving

Arrow functions not working in node --harmony under Ubuntu

送分小仙女□ 提交于 2019-11-30 02:46:00
问题 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 (node.js:119:16) at node.js:906:3 回答1: This should work now

Arrow function “expression expected” syntax error

天涯浪子 提交于 2019-11-30 02:39:01
I want to transform this code: var formatQuoteAmount = function (tx) { return Currency.toSmallestSubunit(tx.usd, 'USD'); }; var quoteAmounts = res.transactions.map(formatQuoteAmount); into an anonymous arrow function. I've written this: var quoteAmounts = res.transactions.map(tx => Currency.toSmallestSubunit(tx.usd, 'USD')); I get expression expected syntax error at the arrow. I looked up the default syntax here and seems like the syntax of my code is correct. Any ideas what the problem might be? I have it working with this syntax: var quoteAmounts = res.transactions.map(function (tx) { return

setInterval function without arrow function

点点圈 提交于 2019-11-29 18:54:01
问题 I am learning about react components following the documentation https://facebook.github.io/react/docs/state-and-lifecycle.html Why do we need to use arrow function here: this.timerID = setInterval(() => this.tick(), 1000); Why can't I just say (obviously it doesn't work) this.timerID = setInterval(this.tick(), 1000); 回答1: The first argument for setInterval is of type function . If you write this: this.timerID = setInterval(this.tick(), 1000); …then you don't pass a function, instead you

What are ES6 arrow functions, how do they work? [duplicate]

人盡茶涼 提交于 2019-11-29 18:52:26
This question already has an answer here: Are 'Arrow Functions' and 'Functions' equivalent / exchangeable? 1 answer I am curious about ES6 arrow functions (fat arrow functions). Are they simply syntactic sugar derived from CoffeeScript, or is there more to them than meets the eye? ES6 Arrow functions in depth One of the prettiest features of ES6, it could easily win a beauty contest, if such a contest would be held. What many people don’t know is that the arrow function is not simply a form of syntactic sugar that we can use instead of the regular callback. As I like to explain it to the

Access variables declared a component from a RxJS subscribe() function

核能气质少年 提交于 2019-11-29 06:12:24
I am able to use this.variable to access variables in any part of the component, except inside RxJS functions like subscribe() or catch() . In the example below, I want to print a message after running a process: import {Component, View} from 'angular2/core'; @Component({ selector: 'navigator' }) @View({ template: './app.component.html', styles: ['./app.component.css'] }) export class AppComponent { message: string; constructor() { this.message = 'success'; } doSomething() { runTheProcess() .subscribe(function(location) { console.log(this.message); }); } } When I run doSomething() , I get

Are ES6 arrow functions incompatible with Angular?

半城伤御伤魂 提交于 2019-11-29 05:58:10
Here's a normal ES5 function in my Angular code which works: app.run(function($templateCache){ $templateCache.put('/some','thing') }); I wanted to convert it to ES6 arrow function app.run($templateCache => $templateCache.put('/some','thing')); but it gives the error Uncaught Error: [$injector:unpr] Unknown provider: '/some'Provider <- '/some' http://errors.angularjs.org/1.4.6/$injector/unpr?p0='%2Fsome'Provider%20%3C-%20'%2Fsome' REGEX_STRING_REGEXP @ angular.js:68 (anonymous function) @ angular.js:4287 getService @ angular.js:4435 (anonymous function) @ angular.js:4292 getService @ angular.js

Javascript ES6, why I can not use `new` with arrow function? [duplicate]

女生的网名这么多〃 提交于 2019-11-29 02:31:41
This question already has an answer here: When should I use Arrow functions in ECMAScript 6? 9 answers As far as I know, arrow function is similar to normal function. There is no problem when I use like this: let X = () => {}; let Y = function() {}; X(); Y(); However, error occurred when I use them with new let X = () => {}; let Y = function() {}; x = new X(); y = new Y(); Uncaught TypeError: X is not a constructor Would you please explain me why? Many thanks. You may wish to clarify your question. Q. What did I do wrong? A. You used new with an arrow function, and that's not allowed. Q. Can I