angular 中的 const {something} = Plugins 是什么意思?
What does const {something} = Plugins mean in angular?
我正在构建一个 ionic 应用程序并观看了 youtube 教程。com/watch?v=bww4a4B43tM 以包含通知。他在这里使用了一个代码,就像
import {Plugins, LocalNotificationEnabledResult,LocalNotificationActionPerformed,LocalNotification,Device} from '@capacitor/core';
const {LocalNotifications} = Plugins;
但是,我无法理解第二行 const {LocalNotifications} = Plugins;
在这里的意思?
我在一些 angular 应用程序中也看到过这种类型的语法,所以我认为它与离子或电容器无关。
这是 JavaScript Destructuring 语法,在您的示例中用于提取嵌套在 TypeScript namespace
中的值,如下所示:
// foo.ts
export namespace Namespace {
export class Class {
public name: string;
}
export function Function() {
}
export const value = 'some value...'
}
// app.ts
import { Namespace } from 'foo.ts';
const { Class, Function, value } = Namespace;
这只是一般的 JS/TS 事情,并不特定于 angular。它称为 Object Destructuring,您可以在其中提取对象的特定属性。
我正在构建一个 ionic 应用程序并观看了 youtube 教程。com/watch?v=bww4a4B43tM 以包含通知。他在这里使用了一个代码,就像
import {Plugins, LocalNotificationEnabledResult,LocalNotificationActionPerformed,LocalNotification,Device} from '@capacitor/core';
const {LocalNotifications} = Plugins;
但是,我无法理解第二行 const {LocalNotifications} = Plugins;
在这里的意思?
我在一些 angular 应用程序中也看到过这种类型的语法,所以我认为它与离子或电容器无关。
这是 JavaScript Destructuring 语法,在您的示例中用于提取嵌套在 TypeScript namespace
中的值,如下所示:
// foo.ts
export namespace Namespace {
export class Class {
public name: string;
}
export function Function() {
}
export const value = 'some value...'
}
// app.ts
import { Namespace } from 'foo.ts';
const { Class, Function, value } = Namespace;
这只是一般的 JS/TS 事情,并不特定于 angular。它称为 Object Destructuring,您可以在其中提取对象的特定属性。