The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Array Comprehensions - NON-STANDARD

Array Comprehensions - NON-STANDARD

2:28
Array Comprehensions didn't make the ES6 cut. You probably shouldn't use them ;) See comments.
Watch this lesson now
Avatar
egghead.io

With ECMAscript 6 you have access to powerful array comprehensions for generating new arrays from existing arrays based on criteria you specify.

Avatar
Sidhartha

This doesn't work anymore with traceur since array comprehensions aren't turned on by default because they were deferred to after ES6 by TC39.

Any idea how to make it work? --array-comprehension gives me a ModuleEvaluationError: Object # has no method 'setProperty'

In reply to egghead.io
Avatar
Yonatan

This doesn't work anymore with traceur since array comprehensions aren't turned on by default because they were deferred to after ES6 by TC39.

Any idea how to make it work? --array-comprehension gives me a ModuleEvaluationError: Object # has no method 'setProperty'

I've verified this doesn't work. It gives a traceur error. I believe this video should either be fixed or removed.

In reply to Sidhartha
Avatar
Mauro

Hey guys,
You should add "arrayComprehension: true" to traceur's options.
https://github.com/google/traceur-compiler/wiki/Options-for-Compiling
Regards!

In reply to Yonatan
Avatar
Andrew

Yeah, maybe this vid should be removed. "Non-standard. Do not use!" here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Array_comprehensions

too bad

In reply to Yonatan
Avatar
Eric

Removed from Babel 6! D:

Avatar
Weng Koon

HOw to make this work in command line?

TestMacBook (master *+) babeltest $ npm run build

babeltest@1.0.0 build /Users/TestMacBook/Documents/egghead/babeltest
babel src -d lib

SyntaxError: src/index.js: Unexpected token (29:14)
27 | ]
28 |

29 | let emails = [for({email, firstName} of people) if(firstName === "Melinda") email]
| ^
30 |
31 |
32 | console.log(emails);

npm ERR! Darwin 15.5.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
npm ERR! node v6.2.1
npm ERR! npm v3.9.3
npm ERR! code ELIFECYCLE
npm ERR! babeltest@1.0.0 build: babel src -d lib
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the babeltest@1.0.0 build script 'babel src -d lib'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the babeltest package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! babel src -d lib
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs babeltest
npm ERR! Or if that isn't available,

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?