Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
223 views
in Technique[技术] by (71.8m points)

javascript - 如何导入子对象(How to import sub objects)

Given these exports in a plugin

(在插件中给出这些导出)

// Imagine these inner functions are written somewhere
export const WindowFunctions={
   maximize: maximizeFunction,
   minimize: minimizeFunction
}

export const FileFunctions={
   open: openFileFunction,
   close: closeFileFunction
}

// Imaging 20 other exports here

export default{
   WindowFunctions,
   FileFunctions,
   // imagine those 20 other exports here too
}

When using require, you could access them with

(使用require时,您可以使用)

const {maximize} = require('yourPlugin').WindowFunctions

How can this be achieved with import instead?

(如何通过import来实现呢?)

So far I have been doing this

(到目前为止,我一直在这样做)

import {WindowFunctions} from 'yourPlugin'
const maximize = WindowFunctions.maximize

Is there a nicer way to import these?

(有没有更好的方法来导入这些?)

Thanks

(谢谢)

  ask by Trevor translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...