Kristofer Koishigawa b3213fc892 fix(i18n): chinese test suite (#38220)
* fix: Chinese test suite

Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working.

* fix: ran script, updated testStrings and solutions
2020-03-03 18:49:47 +05:30

2.7 KiB
Raw Blame History

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
587d7db2367417b2b2512b8c Use an IIFE to Create a Module 1 使用IIFE创建模块

Description

immediately invoked function expression IIFE )通常用于将相关功能分组到单个对象或module 。例如早期的挑战定义了两个mixins
function glideMixinobj{
obj.glide = function{
console.log“在水面上滑行”;
};
}
function flyMixinobj{
obj.fly = function{
console.log“Flyingwooosh;
};
}
我们可以将这些mixins分组到一个模块中,如下所示:
让motionModule =function{
返回{
glideMixinfunctionobj{
obj.glide = function{
console.log“在水面上滑行”;
};
}
flyMixinfunctionobj{
obj.fly = function{
console.log“Flyingwooosh;
};
}
}
}; //两个括号使得函数立即被调用
请注意,您有一个immediately invoked function expression IIFE ),它返回一个对象motionModule 。此返回对象包含作为对象属性的所有mixin行为。 module模式的优点是可以将所有运动行为打包到单个对象中,然后可以由代码的其他部分使用。以下是使用它的示例:
motionModule.glideMixin;
duck.glide;

Instructions

创建一个名为funModulemodule来包装两个mixins isCuteMixinsingMixinfunModule应该返回一个对象。

Tests

tests:
  - text: 应该定义<code>funModule</code>并返回一个对象。
    testString: assert(typeof funModule === "object");
  - text: <code>funModule.isCuteMixin</code>应该访问一个函数。
    testString: assert(typeof funModule.isCuteMixin === "function");
  - text: <code>funModule.singMixin</code>应该访问一个函数。
    testString: assert(typeof funModule.singMixin === "function");

Challenge Seed

let isCuteMixin = function(obj) {
  obj.isCute = function() {
    return true;
  };
};
let singMixin = function(obj) {
  obj.sing = function() {
    console.log("Singing to an awesome tune");
  };
};

Solution

// solution required