首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >这类参数“`const = ({ editor }:{ editor: Editor }) => {}”的含义是什么?

这类参数“`const = ({ editor }:{ editor: Editor }) => {}”的含义是什么?
EN

Stack Overflow用户
提问于 2018-10-19 20:19:45
回答 2查看 68关注 0票数 0

我最近浏览了https://github.com/ory/editor/blob/master/packages/ui/src/Trash/index.js#L89

找到了一种我不明白的论点。以下是完整的代码:

代码语言:javascript
复制
const types = ({ editor }: { editor: Editor }) => {
  const plugins = [
    ...Object.keys(editor.plugins.plugins.layout),
    ...Object.keys(editor.plugins.plugins.content)
  ].map(
    (p: string) =>
      editor.plugins.plugins.content[p].name ||
      editor.plugins.plugins.layout[p].name
  )

  if (editor.plugins.hasNativePlugin()) {
    plugins.push(editor.plugins.getNativePlugin()().name)
  }

  return plugins
}

争论的意义是什么?叫什么来着?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-10-19 20:55:01

它意味着函数将接收具有编辑器属性的对象,并具有编辑器的类型。

有关更多信息,您可以检查https://flow.org/en/

票数 1
EN

Stack Overflow用户

发布于 2018-10-19 21:10:45

这里有两个部分。

  1. 您将解构给定的参数,并且只使用editor属性。 { editor }
  2. 定义传递对象的类型

如果没有类型定义,它看起来就像这样。如果您知道,您只需要传递对象的编辑器,就可以销毁它。

代码语言:javascript
复制
// Passing and working with the whole object
const fn1 = ( obj ) => {
  const editor = obj.editor;
  console.log( editor );
};

// Destructing the object and only use the editor property
// Basically the same as fn1 without the whole obj.
const fn2 = ( { editor } ) => {
  console.log( editor );
};

const obj = {
  editor: 'Editor',
};

fn1( obj );
fn2( obj );

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52899390

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档