* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
1.4 KiB
1.4 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7b8c367417b2b2512b58 | 用 export default 创建一个默认导出 | 1 | 301199 | create-an-export-fallback-with-export-default |
--description--
在export
的课程中,学习了命名导出语法。这可以在其他文件中引用一些函数或者变量。
还需要了解另外一种被称为默认导出的export
的语法。在文件中只有一个值需要导出的时候,通常会使用这种语法。它也常常用于给文件或者模块创建返回值。
下面是一个简单的export default
例子:
// named function
export default function add(x, y) {
return x + y;
}
// anonymous function
export default function(x, y) {
return x + y;
}
注意:当使用export default
去声明一个文件或者模块的返回值时,在每个文件或者模块中应当只默认导出一个值。特别地,能将export deafult
与var
,let
与const
一起使用。
--instructions--
下面的函数应该在这个模块中返回一个值。请添加需要的代码:
--hints--
正确的使用export
进行返回。
assert(
code.match(
/export\s+default\s+function(\s+subtract\s*|\s*)\(\s*x,\s*y\s*\)\s*{/g
)
);
--seed--
--seed-contents--
function subtract(x, y) {
return x - y;
}
--solutions--
export default function subtract(x, y) {
return x - y;
}