From 47caba64abe70eb6c19d7eb8bd17b36a1930a5fb Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Tue, 10 Jun 2025 13:14:23 +0200 Subject: [PATCH] docs: no class inheritance (#47432) Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Erick Zhao --- 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 98909de846e2..29461967d942 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 693363ec4b2e..87f6ead86596 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 78997aabd44f..83bea39c5c1c 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -150,6 +150,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 854de3054601..fcc7135ecfa7 100644 --- a/docs/api/image-view.md +++ b/docs/api/image-view.md @@ -42,6 +42,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 8995d66ba7a7..08a9d63a9817 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 3c53afc222bc..8ee760d1cb44 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 c94d8fe70d79..9ba6ce00242c 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 18339848db6a..3dff6a626962 100644 --- a/docs/api/message-channel-main.md +++ b/docs/api/message-channel-main.md @@ -33,6 +33,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 efaa93b39e21..1c5a6e9c9816 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 a886ea52682a..c1ffd455743b 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 c304f5743083..35f3105416ba 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 6b112def3591..2ffc4dc67184 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 8e0a23a5d8de..5858d08c0abb 100644 --- a/docs/api/view.md +++ b/docs/api/view.md @@ -25,6 +25,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 66bb257cf0ed..802580e26b9b 100644 --- a/docs/api/web-contents-view.md +++ b/docs/api/web-contents-view.md @@ -32,6 +32,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 114731d69d68..9b5e656d8165 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -152,6 +152,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