Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions content/ember/v6/deprecate-classic-class-syntax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
title: "Deprecation: Classic Class Syntax"
until: 7.0.0
since: 6.5.0
---

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably mention the codemod for native classes, as well as a migration path: emberjs/rfcs#1117 (comment)


### `extend`

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.

**Before:**

```javascript
import EmberObject from '@ember/object';

const MyService = EmberObject.extend({
// ...
});
```

**After:**

```javascript
import EmberObject from '@ember/object';

class MyService extends EmberObject {
// ...
}
```

### `reopen`

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.

**Before:**

```javascript
import MyService from './my-service';

MyService.reopen({
// ...
});
```

**After:**

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:

```javascript
import MyService from './my-service';

class ExtendedService extends MyService {
// ...
}
```

### `reopenClass`

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.

**Before:**

```javascript
import MyService from './my-service';

MyService.reopenClass({
isMyService: true,
});
```

**After:**

```javascript
import EmberObject from '@ember/object';

class MyService extends EmberObject {
static isMyService = true;
}
```