One feature of ES2015 that I feel can be a stumbling block (but extremely useful) is Arrow Functions lexical scoping of
Before this addition, every new function defined its own
this - meaning we were required to explicitly bind or locally store the
this reference that we desired in many use-cases.
Whilst working today I came across a test helper function that required a few too many parameters. Debating weather to break the function up, I decided that an elegant solution would be to take advantage of ES2015 object deconstruction and produce a form of ‘Named Parameters’.
Today I stumble upon some code that I did not realise was possible with an
array_map function in PHP.
You are able to supply multiple arrays, which in turn will get ‘zipped up’ and passed to the supplied callback as parameters.
This allows for some rather elegant solutions to the ‘index issue’ and accessing keys from within the callback - both of which are easily achieved in an impertivive mindset.