* 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.5 KiB
1.5 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7b8c367417b2b2512b57 | 用 * 从文件中导入所有内容 | 1 | 301210 | use--to-import-everything-from-a-file |
--description--
我们还可以用import
语法从文件中导入所有的内容。下面是一个从同目录下的"math_functions"
文件中导入所有内容的例子:
import * as myMathModule from "./math_functions.js";
上面的 import
语句会创建一个叫做 myMathModule
的对象。这只是一个变量名,可以随便命名。对象包含 math_functions.js
文件里的所有导出,可以像访问对象的属性那样访问里面的函数。下面是使用导入的 add
和 subtract
函数的例子:
myMathModule.add(2,3);
myMathModule.subtract(5,3);
--instructions--
下面的代码需要从同目录下的"string_functions"
文件中导入所有内容。使用提供的对象,在当前文件的顶部添加正确的import *
语句
--hints--
正确使用import * as
语法。
assert(
code.match(
/import\s*\*\s*as\s+stringFunctions\s+from\s*('|")\.\/string_functions\.js\1/g
)
);
--seed--
--seed-contents--
// Only change code above this line
stringFunctions.uppercaseString("hello");
stringFunctions.lowercaseString("WORLD!");
--solutions--
import * as stringFunctions from "./string_functions.js";
// add code above this line
stringFunctions.uppercaseString("hello");
stringFunctions.lowercaseString("WORLD!");