Skip to content

Commit f38de30

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

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
id: deprecate-classic-class-syntax
3+
title: "Deprecation: Classic Class Syntax"
4+
---
5+
6+
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.
7+
8+
### `extend`
9+
10+
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.
11+
12+
**Before:**
13+
14+
```javascript
15+
import EmberObject from '@ember/object';
16+
17+
const MyComponent = EmberObject.extend({
18+
// ...
19+
});
20+
```
21+
22+
**After:**
23+
24+
```javascript
25+
import EmberObject from '@ember/object';
26+
27+
class MyComponent extends EmberObject {
28+
// ...
29+
}
30+
```
31+
32+
### `reopen`
33+
34+
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.
35+
36+
**Before:**
37+
38+
```javascript
39+
import MyComponent from './my-component';
40+
41+
MyComponent.reopen({
42+
// ...
43+
});
44+
```
45+
46+
**After:**
47+
48+
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:
49+
50+
```javascript
51+
import MyComponent from './my-component';
52+
53+
class ExtendedComponent extends MyComponent {
54+
// ...
55+
}
56+
```
57+
58+
### `reopenClass`
59+
60+
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.
61+
62+
**Before:**
63+
64+
```javascript
65+
import MyComponent from './my-component';
66+
67+
MyComponent.reopenClass({
68+
isMyComponent: true,
69+
});
70+
```
71+
72+
**After:**
73+
74+
```javascript
75+
import EmberObject from '@ember/object';
76+
77+
class MyComponent extends EmberObject {
78+
static isMyComponent = true;
79+
}
80+
```

0 commit comments

Comments
 (0)