-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Feature request: support .find
and .findIndex
methods of Array instances by default
#7339
Comments
Surprising absolutely nobody, I'm sure, I still think this is an antipattern, for all the reasons I enumerated in #6999. The existence of |
I agree with you but still I don't understand why node can't make |
As far as I've seen in #6999, there were a couple or reasons:
(Point out if I miss another reason.) The counterarguments are the following:
|
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 |
it's so easy to shim in userland so it ain't worth creating github issue |
Enabling these methods in Node.js seems easy as well: A shim is fine, but it reinvents the existing V8 wheel. |
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. |
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 equivalentfor
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:
array.prototype.find
andarray.prototype.findindex
are made by @paulmillr and are available in the npm registry. The idea of this issue is to make these polyfills unnecessary in newer versions of Node. These two modules may seem unpopular, but that's because many people use their code as a part (i.e. not a dependency) of a larger module —es6-shim
.The text was updated successfully, but these errors were encountered: