Skip to content

Commit 8e9f588

Browse files
committed
Merge pull request #136 from alexspeller/contains-to-includes
Add contains to includes RFC
2 parents 3d43d6d + b81ccfb commit 8e9f588

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

text/0000-contains-to-includes.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
- Start Date: 2016-04-16
2+
- RFC PR: (leave this empty)
3+
- Ember Issue: (leave this empty)
4+
5+
# Summary
6+
7+
[`contains`](http://emberjs.com/api/classes/Ember.Array.html#method_contains) is
8+
implemented on `Ember.Array`, but [contains was renamed to includes in 2014]
9+
(https://github.com/tc39/Array.prototype.includes/commit/4b6b9534582cb7991daea3980c26a34af0e76c6c)
10+
- this proposal is for `contains` to be deprecated in favour of an `includes`
11+
method on `Ember.Array`
12+
13+
# Motivation
14+
15+
Motivation is to stay in line with web standards
16+
17+
# Detailed design
18+
19+
First, implement `includes` polyfill in compliance with `includes` spec. Polyfill
20+
sample from MDN is:
21+
22+
```js
23+
if (!Array.prototype.includes) {
24+
Array.prototype.includes = function(searchElement /*, fromIndex*/ ) {
25+
'use strict';
26+
var O = Object(this);
27+
var len = parseInt(O.length) || 0;
28+
if (len === 0) {
29+
return false;
30+
}
31+
var n = parseInt(arguments[1]) || 0;
32+
var k;
33+
if (n >= 0) {
34+
k = n;
35+
} else {
36+
k = len + n;
37+
if (k < 0) {k = 0;}
38+
}
39+
var currentElement;
40+
while (k < len) {
41+
currentElement = O[k];
42+
if (searchElement === currentElement ||
43+
(searchElement !== searchElement && currentElement !== currentElement)) { // NaN !== NaN
44+
return true;
45+
}
46+
k++;
47+
}
48+
return false;
49+
};
50+
}
51+
```
52+
53+
Then, alias `contains` to `includes` with deprecation warning, deprecate in line with standard
54+
deprecation process. I don't believe that adding the additional parameter will
55+
have any affect on existing usage of `contains`.
56+
57+
# How We Teach This
58+
59+
* Update any references in docs and guides to `includes`
60+
* Write a deprecation guide, mentioning any edge cases where the new `includes` behaves differently to `contains`, and giving migration examples
61+
* Indicate in api docs that this is a polyfill
62+
63+
# Drawbacks
64+
65+
* May break existing apps
66+
* [Was considered before but was too early](https://github.com/emberjs/ember.js/issues/5670#issuecomment-64084814)
67+
68+
# Alternatives
69+
70+
Keep current methods
71+
72+
# Unresolved questions
73+
74+
None

0 commit comments

Comments
 (0)