Typescript/Javascript forEach call -


i having trouble understanding bit of code:

stringsarray.foreach(s => {     (var name in validators) {         console.log('"' + s + '" ' +             (validators[name].isacceptable(s) ?                 ' matches ' : ' doesnt match ') + name);     } }); 

in particular, s => { ... part mysterious. looks s being assigned next string in array on each loop. => part meaning? it's related lambdas think not following. newbie? thanks!

yeah it's lambda (for example, similar ecmascript6 , ruby, other languages.)

array.prototype.foreach takes 3 arguments, element, index, array, s parameter name being used element.

it'd writing in regular ecmascript5:

stringsarray.foreach(function(s) {     (var name in validators) {         console.log('"' + s + '" ' +             (validators[name].isacceptable(s) ?                 ' matches ' : ' doesnt match ') + name);     } }); 

in above example, didn't show whole code, assume validators plain object {}.

the syntax example gave identical es6 syntax.

check out example the typescript handbook:

example


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -