freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/es6/create-an-export-fallback-with-export-default.chinese.md

1.7 KiB
Raw Blame History

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
587d7b8c367417b2b2512b58 Create an Export Fallback with export default 1 使用导出默认值创建导出回退

Description

export课程中,您了解了称为命名导出的语法。这使您可以使多个函数和变量可用于其他文件。您需要知道另一种export语法,称为导出默认值 。通常,如果只从文件导出一个值,您将使用此语法。它还用于为文件或模块创建回退值。以下是export default的快速示例:
export default function addxy{
返回x + y;
}
注意:由于export default用于声明模块或文件的回退值,因此每个模块或文件中只能有一个值作为默认导出。此外,您不能将export default用于var letconst

Instructions

以下函数应该是模块的回退值。请添加必要的代码。

Tests

tests:
  - text: 适当使用<code>export</code>回落。
    testString: 'getUserInput => assert(getUserInput("index").match(/export\s+default\s+function\s+subtract\(x,y\)\s+{return\s+x\s-\s+y;}/g), "Proper used of <code>export</code> fallback.");'

Challenge Seed

"use strict";
function subtract(x,y) {return x - y;}

Before Test

window.exports = function(){};

Solution

// solution required