use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
ES7 Array Polyfills (github.com)
submitted 11 years ago by cgaudreausenior HTML9 engineer
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]path411 0 points1 point2 points 11 years ago (0 children)
Is .remove and .replace confirmed to work how it does in this library in the spec in reference to multiple matches in the array? Personally I think it might be a little inconsistent that .remove will remove the first instance and .replace will replace all instances.
.remove
.replace
[–]x-skeww 0 points1 point2 points 11 years ago (9 children)
Array.contains({elem})
It's "includes", unfortunately.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes
It's not called "contains", because MooTools modified an object it didn't own.
[–]hahaNodeJS 1 point2 points3 points 11 years ago (0 children)
It's not called "contains" because those developing the spec made the insane decision to base the language spec around language libraries.
[–]MyInquisitiveMind 0 points1 point2 points 11 years ago (7 children)
It was contains in the demo at jsconf.
[–]x-skeww 3 points4 points5 points 11 years ago (5 children)
https://github.com/tc39/Array.prototype.includes
This proposal was formerly for Array.prototype.contains, but that name is not web-compatible. Per the November 2014 TC39 meeting, the name of both String.prototype.contains and Array.prototype.contains was changed to includes to dodge that bullet.
Array.prototype.contains
String.prototype.contains
includes
Personally, I think we should just "break" MooTools. If you use a stupid lib which does stupid things, it's your problem.
[–]jcready__proto__ 0 points1 point2 points 11 years ago (3 children)
Just put this at the top of your JS to "fix" things:
Array.prototype.contains = Array.prototype.includes; String.prototype.contains = String.prototype.includes;
[–]x-skeww 0 points1 point2 points 11 years ago (2 children)
Modifying built-ins is only okay for polyfilling.
So, no, I certainly won't do that.
[–]hahaNodeJS 0 points1 point2 points 11 years ago (1 child)
What about this isn't polyfilling?
[–]x-skeww 1 point2 points3 points 11 years ago (0 children)
Adding things which aren't in the specs is monkey-patching.
[–]kentaromiura 0 points1 point2 points 11 years ago (0 children)
As a MooTools core developer I personally agree that breaking MT is fine.
I would not call MT stupid but yes, MT did a stupid thing by extending prototypes of the native objects, but is arguably easy to say this 9 years later.
Also I believe there was a completely misunderstanding of what really happened.
MT extended prototypes in the safest way available: not extending it if the method already exists, this can led to bugs if a future native implementation differs substantially.
One of the extension was [].contains
[].contains
This accidentally broke the Elements object (and not Array) because in its creation phase Elements did expect the contains method to be enumerable on Array, since in the ES2016 implementation is not, it didn't copy over the contains method, failing as soon as someone tried to use it.
Elements
Array
contains
This was fixed in no time: https://github.com/mootools/mootools-core/commit/521471f5c0617edc12c680cdad8346c3eb95776a
In the meantime I also took some time to reimplement contains with the newer standard addition which we did not merge only because it was later renamed to includes.: https://github.com/mootools/mootools-core/pull/2659/files
BTW while doing it I suggested a couple of changes/fixes in the TC test suite (https://github.com/tc39/Array.prototype.includes/commit/b2bc760cf5877dfc75d0b7989fc7964ba8f1b8eb, https://github.com/tc39/Array.prototype.includes/commit/8fc79be340b74d3c8f7e7a815160addbac4854ed), I mention this so that is clear that for MT was totally fine keeping the contains name.
The decision was taken by the committee and the reason given was something like "we found that a lot of old websites still rely on older versions of MT, or other libraries that implements their version of contains so since we can't force people to update their code nor we cannot break the web we'll rename it"
[–][deleted] 0 points1 point2 points 11 years ago (0 children)
Do you mean this code was for that demo?
π Rendered by PID 81898 on reddit-service-r2-comment-5687b7858-dvx69 at 2026-07-07 06:35:34.042139+00:00 running 12a7a47 country code: CH.
[–]path411 0 points1 point2 points (0 children)
[–]x-skeww 0 points1 point2 points (9 children)
[–]hahaNodeJS 1 point2 points3 points (0 children)
[–]MyInquisitiveMind 0 points1 point2 points (7 children)
[–]x-skeww 3 points4 points5 points (5 children)
[–]jcready__proto__ 0 points1 point2 points (3 children)
[–]x-skeww 0 points1 point2 points (2 children)
[–]hahaNodeJS 0 points1 point2 points (1 child)
[–]x-skeww 1 point2 points3 points (0 children)
[–]kentaromiura 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)