Skip to content

Commit 6b3ad38

Browse files
committed
add deprecation guide for String prototype extensions
1 parent 9680f66 commit 6b3ad38

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
id: ember-string.prototype_extensions
3+
title: Deprecate String prototype extensions
4+
until: '4.0.0'
5+
since: 'Upcoming Features'
6+
---
7+
8+
Ember applications add methods to the `String` prototype by default, making you able to call `"Tomster".dasherize()`, for example.
9+
Calling [these methods](https://api.emberjs.com/ember/3.22/classes/String) on a string itself should be replaced with importing the function from `@ember/string`.
10+
11+
Before:
12+
13+
```js
14+
let mascot = "Empress Zoey";
15+
16+
mascot.camelize(); //=> empressZoey
17+
mascot.capitalize(); //=> "Empress Zoey"
18+
mascot.classify(); //=> "EmpressZoey"
19+
mascot.decamelize(); //=> "empress zoey"
20+
mascot.underscore(); //=> "empress_zoey"
21+
mascot.w(); //=> [ "Empress", "Zoey" ]
22+
```
23+
24+
After:
25+
26+
```js
27+
let mascot = "Empress Zoey";
28+
29+
camelize(mascot); //=> empressZoey
30+
capitalize(mascot); //=> "Empress Zoey"
31+
classify(mascot); //=> "EmpressZoey"
32+
decamelize(mascot); //=> "empress zoey"
33+
underscore(mascot); //=> "empress_zoey"
34+
w(mascot); //=> [ "Empress", "Zoey" ]
35+
```
36+
37+
You might want to replace these methods with another library, like [lodash](https://lodash.com/).
38+
Keep in mind that different libraries will behave in slightly different ways, so make sure any critical transformation is thoroughly tested.
39+
40+
You can also [disable String prototype extensions](https://guides.emberjs.com/release/configuring-ember/disabling-prototype-extensions/) by editing your environment file:
41+
42+
```js
43+
// config/environment.js
44+
ENV = {
45+
EmberENV: {
46+
EXTEND_PROTOTYPES: {
47+
Date: false,
48+
String: false,
49+
}
50+
}
51+
}
52+
```

0 commit comments

Comments
 (0)