Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* 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>
2021-01-12 19:31:00 -07:00

1.7 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d7b8c367417b2b2512b55 通过 import 复用 JavaScript 代码 1 301208 reuse-javascript-code-using-import

--description--

import 可以导入文件或模块的一部分。在之前的课程里,例子从 math_functions.js 文件里导出了 add,下面看一下如何在其它的文件导入它:

import { add } from './math_functions.js';

在这里,import 会在 math_functions.js 里找到 add,只导入这个函数,忽略剩余的部分。./ 告诉程序在当前文件的相同目录寻找 math_functions.js 文件。用这种方式导入时,相对路径(./)和文件扩展名(.js)都是必需的。

可以在导入语句里导入多个项目,如下:

import { add, subtract } from './math_functions.js';

--instructions--

添加 import 语句,使当前文件可以使用你在之前课程里导出的 uppercaseStringlowercaseString 函数,函数在当前路径下的 string_functions.js 文件里。

--hints--

应该导入 uppercaseString

assert(
  code.match(
    /import\s*{\s*(uppercaseString[^}]*|[^,]*,\s*uppercaseString\s*)}\s+from\s+('|")\.\/string_functions\.js\2/g
  )
);

应该导入 lowercaseString

assert(
  code.match(
    /import\s*{\s*(lowercaseString[^}]*|[^,]*,\s*lowercaseString\s*)}\s+from\s+('|")\.\/string_functions\.js\2/g
  )
);

--seed--

--seed-contents--

  
// Only change code above this line

uppercaseString("hello");
lowercaseString("WORLD!");

--solutions--

import { uppercaseString, lowercaseString } from './string_functions.js';

uppercaseString("hello");
lowercaseString("WORLD!");