1.9 KiB
1.9 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7b8c367417b2b2512b57 | Use * to Import Everything from a File | 1 | 使用*从文件导入所有内容 |
Description
"math_functions"
的文件的内容被导入到同一目录中的文件中: 从“math_functions”导入*作为myMathModule;并打破代码:
myMathModule.add(2,3);
myMathModule.subtract(5,3);
从“file_path_goes_here”导入* as object_with_name_of_your_choice您可以使用
object_with_name_of_your_choice.imported_function
import * as
后面的任何名称import * as
语句的一部分。为了使用此方法,它需要一个接收导入值的对象。从这里,您将使用点表示法来调用导入的值。 Instructions
"capitalize_strings"
的内容。使用提供的对象将相应的import *
语句添加到文件的顶部。 Tests
tests:
- text: 正确使用<code>import * as</code>语法。
testString: 'assert(code.match(/import\s+\*\s+as\s+[a-zA-Z0-9_$]+\s+from\s*"\s*capitalize_strings\s*"\s*;/gi), "Properly uses <code>import * as</code> syntax.");'
Challenge Seed
"use strict";
Before Test
window.require = function(str) {
if (str === 'capitalize_strings') {
return {
capitalize: str => str.toUpperCase(),
lowercase: str => str.toLowerCase()
}}};
Solution
// solution required