Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Feature request: support .find and .findIndex methods of Array instances by default #7339

Closed
Mithgol opened this issue Mar 22, 2014 · 8 comments

Comments

@Mithgol
Copy link

Mithgol commented Mar 22, 2014

Harmony (ECMAScript 6) methods .find and .findIndex are supported in Firefox (since version 25, says MDN) and in Chrome (since version 30 or earlier, says ECMAScript 6 compatibility table by kangax; these methods have to be enabled via “Experimental JavaScript features” flag in Chrome). Both methods are semantically better than the equivalent for loops (and, most likely, they're also more performant), and thus it's relatively easy to grow accustomed to these methods.

Node 0.11 does also support .find and .findIndex, but requires --harmony_arrays V8 option. Could this option be enabled by default in Node?


Notes:

@othiym23
Copy link

Surprising absolutely nobody, I'm sure, I still think this is an antipattern, for all the reasons I enumerated in #6999. The existence of es6-shim actually argues against turning this on in core, as it's very simple for people to add these features via npm.

@paulmillr
Copy link

I agree with you but still I don't understand why node can't make —harmony-* flags default. That would make a lot of very nice ES6 stuff available today. For example, generators.

@bnoordhuis
Copy link
Member

I don't understand why node can't make —harmony-* flags default

See #6999 for rationale.

EDIT: @othiym23 also links to it; I'd say the key point is TJ's closing remark: let's leave it up to V8 to enable harmony features.

@Mithgol
Copy link
Author

Mithgol commented Mar 23, 2014

@othiym23

I still think this is an antipattern, for all the reasons I enumerated in #6999.

As far as I've seen in #6999, there were a couple or reasons:

  • It's not appropriate to turn on ES6 in Node by default until V8 has had a chance to get their implementation in line with the standard, which is still a few months away from being complete.
  • Stable major versions of Node (such as 0.10, 0.12, 1.0) should clearly correspond (feature-wise) to stable minor versions of V8 (3.22, 3.23, 3.24).

(Point out if I miss another reason.)

The counterarguments are the following:

  • Unlike some other harmony features mentioned in src: enable --harmony by default #6999 (such as harmony proxies or harmony promises), the V8 implementation of .find and .findIndex seems already in line with the standard and complete (since August 2013). The standard itself is in a draft stage, but this part of it is unlikely to change.
  • These methods should indeed appear in a new stable version of Node (i.e. not in a minor patch of the previous stable version) and be documented in the corresponding “API changes” section of the Node's wiki and blog — not to create any surprises.

@Mithgol
Copy link
Author

Mithgol commented Mar 23, 2014

@bnoordhuis

I'd say the key point is TJ's closing remark: let's leave it up to V8 to enable harmony features.

TJ may have said that about your idea of enabling the whole set of harmony features. However, that decision is (I hope) less applicable to a smaller, separate, isolated set of harmony features as small as a couple of methods, especially because these features seem to be implemented very close to the standard, because they stay the same (in the draft and in the V8 source) in a half of a year, because they don't seem deep and dangerous, and because they are also adopted in Firefox.

The V8 devs might adopt “all or nothing” approach and put all harmony features together on hold until ES6 becomes the new ECMAScript standard. But, when I look at .find and .findIndex, I always ask myself: what in these two methods deserves several more years of staying out of the default set of core features?

@rlidwka
Copy link

rlidwka commented Mar 23, 2014

it's so easy to shim in userland so it ain't worth creating github issue

@Mithgol
Copy link
Author

Mithgol commented Mar 23, 2014

Enabling these methods in Node.js seems easy as well: V8::SetFlagsFromString("--harmony_arrays", sizeof("--harmony_arrays") - 1);.

A shim is fine, but it reinvents the existing V8 wheel.

@tjfontaine
Copy link

I did something similar to this months ago with https://www.npmjs.org/package/setflags which probably needs more updating now -- the problem is it's a bit unfortunate to let modules tweak these flags when the node process wasn't spun up with it initially.

I'm going to hold the line for now on not shimming or getting in front of v8 for now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants