Skip to content

Commit 2c618b5

Browse files
committed
Add Classic Classes Deprecation Guide
1 parent fb67e7b commit 2c618b5

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
title: "Deprecation: Classic Class Syntax"
3+
until: 7.0.0
4+
since: 6.5.0
5+
---
6+
7+
With the introduction of native class syntax in JavaScript, Ember is deprecating its classic class syntax, which includes `extend`, `reopen`, and `reopenClass`. This guide will help you migrate your code to the modern syntax.
8+
9+
### `extend`
10+
11+
The `extend` method was used to create a new class that inherited from a parent class. This can be replaced with the `class` and `extends` keywords in native JavaScript.
12+
13+
**Before:**
14+
15+
```javascript
16+
import EmberObject from '@ember/object';
17+
18+
const MyComponent = EmberObject.extend({
19+
// ...
20+
});
21+
```
22+
23+
**After:**
24+
25+
```javascript
26+
import EmberObject from '@ember/object';
27+
28+
class MyComponent extends EmberObject {
29+
// ...
30+
}
31+
```
32+
33+
### `reopen`
34+
35+
The `reopen` method was used to modify an existing class by adding new properties and methods. This is a risky pattern because it modifies the class for all consumers, which can lead to unexpected behavior. There is no direct replacement for `reopen`. Instead, you should refactor your code to avoid modifying classes at runtime. If you must add functionality, consider using composition or creating a subclass.
36+
37+
**Before:**
38+
39+
```javascript
40+
import MyComponent from './my-component';
41+
42+
MyComponent.reopen({
43+
// ...
44+
});
45+
```
46+
47+
**After:**
48+
49+
There is no direct replacement for `reopen`. You should refactor your code to avoid this pattern. If you need to add functionality, consider creating a subclass:
50+
51+
```javascript
52+
import MyComponent from './my-component';
53+
54+
class ExtendedComponent extends MyComponent {
55+
// ...
56+
}
57+
```
58+
59+
### `reopenClass`
60+
61+
The `reopenClass` method was used to add static properties and methods to a class. This can be replaced with the `static` keyword in native JavaScript.
62+
63+
**Before:**
64+
65+
```javascript
66+
import MyComponent from './my-component';
67+
68+
MyComponent.reopenClass({
69+
isMyComponent: true,
70+
});
71+
```
72+
73+
**After:**
74+
75+
```javascript
76+
import EmberObject from '@ember/object';
77+
78+
class MyComponent extends EmberObject {
79+
static isMyComponent = true;
80+
}
81+
```

0 commit comments

Comments
 (0)