From 6aa3665b960ee1e7ce047ee66f51f7c31b30449b Mon Sep 17 00:00:00 2001 From: Erick Zhao Date: Tue, 10 Jun 2025 01:00:06 -0700 Subject: [PATCH] docs: no class inheritance (#47403) --- docs/api/base-window.md | 4 ++++ docs/api/browser-view.md | 4 ++++ docs/api/browser-window.md | 4 ++++ docs/api/image-view.md | 4 ++++ docs/api/ipc-main-service-worker.md | 4 ++++ docs/api/menu-item.md | 4 ++++ docs/api/menu.md | 4 ++++ docs/api/message-channel-main.md | 4 ++++ docs/api/notification.md | 13 +++++++------ docs/api/share-menu.md | 4 ++++ docs/api/touch-bar.md | 4 ++++ docs/api/tray.md | 4 ++++ docs/api/view.md | 4 ++++ docs/api/web-contents-view.md | 4 ++++ docs/faq.md | 8 ++++++++ 15 files changed, 67 insertions(+), 6 deletions(-) diff --git a/docs/api/base-window.md b/docs/api/base-window.md index e7920554732..e56530eed58 100644 --- a/docs/api/base-window.md +++ b/docs/api/base-window.md @@ -99,6 +99,10 @@ Process: [Main](../glossary.md#main-process) It creates a new `BaseWindow` with native properties as set by the `options`. +> [!WARNING] +> Electron's built-in classes cannot be subclassed in user code. +> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules). + ### `new BaseWindow([options])` * `options` [BaseWindowConstructorOptions](structures/base-window-options.md?inline) (optional) diff --git a/docs/api/browser-view.md b/docs/api/browser-view.md index 693363ec4b2..87f6ead8659 100644 --- a/docs/api/browser-view.md +++ b/docs/api/browser-view.md @@ -38,6 +38,10 @@ Process: [Main](../glossary.md#main-process) This module cannot be used until the `ready` event of the `app` module is emitted. +> [!WARNING] +> Electron's built-in classes cannot be subclassed in user code. +> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules). + ### Example ```js diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index ae35033ccef..0f488b1388a 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -151,6 +151,10 @@ Process: [Main](../glossary.md#main-process) It creates a new `BrowserWindow` with native properties as set by the `options`. +> [!WARNING] +> Electron's built-in classes cannot be subclassed in user code. +> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules). + ### `new BrowserWindow([options])` * `options` [BrowserWindowConstructorOptions](structures/browser-window-options.md?inline) (optional) diff --git a/docs/api/image-view.md b/docs/api/image-view.md index edc93fa7e89..b55711c3a1b 100644 --- a/docs/api/image-view.md +++ b/docs/api/image-view.md @@ -43,6 +43,10 @@ Process: [Main](../glossary.md#main-process) `ImageView` is an [EventEmitter][event-emitter]. +> [!WARNING] +> Electron's built-in classes cannot be subclassed in user code. +> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules). + ### `new ImageView()` _Experimental_ Creates an ImageView. diff --git a/docs/api/ipc-main-service-worker.md b/docs/api/ipc-main-service-worker.md index 8995d66ba7a..08a9d63a981 100644 --- a/docs/api/ipc-main-service-worker.md +++ b/docs/api/ipc-main-service-worker.md @@ -11,6 +11,10 @@ Process: [Main](../glossary.md#main-process) +> [!WARNING] +> Electron's built-in classes cannot be subclassed in user code. +> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules). + ### Instance Methods #### `ipcMainServiceWorker.on(channel, listener)` diff --git a/docs/api/menu-item.md b/docs/api/menu-item.md index e73486ea444..980b27d2dee 100644 --- a/docs/api/menu-item.md +++ b/docs/api/menu-item.md @@ -6,6 +6,10 @@ Process: [Main](../glossary.md#main-process) See [`Menu`](menu.md) for examples. +> [!WARNING] +> Electron's built-in classes cannot be subclassed in user code. +> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules). + ### `new MenuItem(options)` * `options` Object diff --git a/docs/api/menu.md b/docs/api/menu.md index c94d8fe70d7..9ba6ce00242 100644 --- a/docs/api/menu.md +++ b/docs/api/menu.md @@ -6,6 +6,10 @@ Process: [Main](../glossary.md#main-process) +> [!WARNING] +> Electron's built-in classes cannot be subclassed in user code. +> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules). + ### `new Menu()` Creates a new menu. diff --git a/docs/api/message-channel-main.md b/docs/api/message-channel-main.md index 39c8b6cfce8..8e0a5e41233 100644 --- a/docs/api/message-channel-main.md +++ b/docs/api/message-channel-main.md @@ -37,6 +37,10 @@ ipcRenderer.on('port', (e) => { }) ``` +> [!WARNING] +> Electron's built-in classes cannot be subclassed in user code. +> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules). + ### Instance Properties #### `channel.port1` diff --git a/docs/api/notification.md b/docs/api/notification.md index efaa93b39e2..1c5a6e9c981 100644 --- a/docs/api/notification.md +++ b/docs/api/notification.md @@ -4,12 +4,9 @@ Process: [Main](../glossary.md#main-process) -:::info Renderer process notifications - -If you want to show notifications from a renderer process you should use the -[web Notifications API](../tutorial/notifications.md) - -::: +> [!NOTE] +> If you want to show notifications from a renderer process you should use the +> [web Notifications API](../tutorial/notifications.md) ## Class: Notification @@ -21,6 +18,10 @@ Process: [Main](../glossary.md#main-process) It creates a new `Notification` with native properties as set by the `options`. +> [!WARNING] +> Electron's built-in classes cannot be subclassed in user code. +> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules). + ### Static Methods The `Notification` class has the following static methods: diff --git a/docs/api/share-menu.md b/docs/api/share-menu.md index a886ea52682..c1ffd455743 100644 --- a/docs/api/share-menu.md +++ b/docs/api/share-menu.md @@ -13,6 +13,10 @@ For including the share menu as a submenu of other menus, please use the Process: [Main](../glossary.md#main-process) +> [!WARNING] +> Electron's built-in classes cannot be subclassed in user code. +> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules). + ### `new ShareMenu(sharingItem)` * `sharingItem` SharingItem - The item to share. diff --git a/docs/api/touch-bar.md b/docs/api/touch-bar.md index c304f574308..35f3105416b 100644 --- a/docs/api/touch-bar.md +++ b/docs/api/touch-bar.md @@ -1,5 +1,9 @@ # TouchBar +> [!WARNING] +> Electron's built-in classes cannot be subclassed in user code. +> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules). + ## Class: TouchBar > Create TouchBar layouts for native macOS applications diff --git a/docs/api/tray.md b/docs/api/tray.md index 6b112def359..2ffc4dc6718 100644 --- a/docs/api/tray.md +++ b/docs/api/tray.md @@ -25,6 +25,10 @@ app.whenReady().then(() => { }) ``` +> [!WARNING] +> Electron's built-in classes cannot be subclassed in user code. +> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules). + **Platform Considerations** **Linux** diff --git a/docs/api/view.md b/docs/api/view.md index 2eb7f0a4b4b..a3388a92e08 100644 --- a/docs/api/view.md +++ b/docs/api/view.md @@ -26,6 +26,10 @@ Process: [Main](../glossary.md#main-process) `View` is an [EventEmitter][event-emitter]. +> [!WARNING] +> Electron's built-in classes cannot be subclassed in user code. +> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules). + ### `new View()` Creates a new `View`. diff --git a/docs/api/web-contents-view.md b/docs/api/web-contents-view.md index 1ab79632fcf..cae7dabfc56 100644 --- a/docs/api/web-contents-view.md +++ b/docs/api/web-contents-view.md @@ -33,6 +33,10 @@ Process: [Main](../glossary.md#main-process) `WebContentsView` is an [EventEmitter][event-emitter]. +> [!WARNING] +> Electron's built-in classes cannot be subclassed in user code. +> For more information, see [the FAQ](../faq.md#class-inheritance-does-not-work-with-electron-built-in-modules). + ### `new WebContentsView([options])` * `options` Object (optional) diff --git a/docs/faq.md b/docs/faq.md index 22969c542bb..b7259d1661b 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -156,6 +156,14 @@ The effect is visible only on (some?) LCD screens. Even if you don't see a diffe Notice that just setting the background in the CSS does not have the desired effect. +## Class inheritance does not work with Electron built-in modules + +Electron classes cannot be subclassed with the [`extends`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/extends) +keyword (also known as class inheritance). This feature was never implemented in Electron due +to the added complexity it would add to C++/JavaScript interop in Electron's internals. + +For more information, see [electron/electron#23](https://github.com/electron/electron/issues/23). + [memory-management]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management [closures]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures [storage]: https://developer.mozilla.org/en-US/docs/Web/API/Storage