Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[选择题] 63.(单选题)我们怎样才能在indexjs中调用sum.js中的sum ? #1041

Open
qiilee opened this issue Apr 15, 2020 · 0 comments

Comments

@qiilee
Copy link
Member

qiilee commented Apr 15, 2020

// sum.js
export default function sum(x) { 
  return x + x;
}

// index.js
import * as sum from './sum';
A:sum(4)
B: sum.sum(4)
C: sum.default(4)
D: 默认导出不用*来导入,只能具名导出 

答案:C

解析:

使用符号*,我们引入文件中的所有值,包括默认和具分章
名。如果我们有以下文件:

// info.js
export const name = 'Lydia';
export const age = 21;
export default 'I love JavaScript';

// index.js
import * as info from './info'; 
console.log(info);

将会输出以下内容:

{
  default: 'I love JavaScript',
  name: 'Lydia',
  age: 21
}

以sum为例,相当于以下形式引入值sum :

{ default: function sum(x) { return x + x }}

我们可以通过调用sum.default来调用该函数

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant