chore(i18n,curriculum): processed translations (#42581)
This commit is contained in:
@ -17,7 +17,7 @@ Animal.prototype.eat = function() {
|
||||
};
|
||||
```
|
||||
|
||||
在这一节以及下一节挑战中我们将学习如何在 `Bird` 和 `Dog` 中重用 `Animal's` 中的方法,而无需重新定义它们。 这里我们会用到构造函数的继承特性。 这一节挑战中我们学习第一步:创建一个超类 `supertype`(或者叫父类)的实例。 你已经学会了一种创建 `Animal` 实例的方法,即使用 `new` 操作符:
|
||||
在这一节以及下一节挑战中我们将学习如何在 `Bird` 和 `Dog` 中重用 `Animal` 中的方法,而无需重新定义它们。 这里我们会用到构造函数的继承特性。 这一节挑战中我们学习第一步:创建一个超类 `supertype`(或者叫父类)的实例。 你已经学会了一种创建 `Animal` 实例的方法,即使用 `new` 操作符:
|
||||
|
||||
```js
|
||||
let animal = new Animal();
|
||||
@ -29,7 +29,7 @@ let animal = new Animal();
|
||||
let animal = Object.create(Animal.prototype);
|
||||
```
|
||||
|
||||
`Object.create(obj)` 创建了一个新对象,并指定了 `obj` 作为新对象的 `prototype`。 回忆一下,我们之前说过 `prototype` 就像是创建对象的“配方”。 如果我们把 `animal` 的 `prototype` 设置为与 `Animal's` 构造函数的 `prototype` 一样,那么就相当于让 `animal` 这个实例的配方与 `Animal` 其他实例的配方一样了。
|
||||
`Object.create(obj)` 创建了一个新对象,并指定了 `obj` 作为新对象的 `prototype`。 回忆一下,我们之前说过 `prototype` 就像是创建对象的“配方”。 如果我们把 `animal` 的 `prototype` 设置为与 `Animal` 构造函数的 `prototype` 一样,那么就相当于让 `animal` 这个实例具有与 `Animal` 的其他实例相同的“配方”了。
|
||||
|
||||
```js
|
||||
animal.eat();
|
||||
|
@ -36,7 +36,7 @@ Bird.prototype.eat = function() {
|
||||
};
|
||||
```
|
||||
|
||||
如果你有一个实例:`let duck = new Bird();`,然后你调用了 `duck.eat()`,以下就是 JavaScript 在 `duck’s` 的 `prototype` 链上寻找方法的过程:
|
||||
如果你有一个实例:`let duck = new Bird();`,然后你调用了 `duck.eat()`,以下就是 JavaScript 在 `duck` 的 `prototype` 链上寻找方法的过程:
|
||||
|
||||
1. `duck` => `eat()` 是定义在这里吗? 不是。
|
||||
2. `Bird` => `eat()` 是定义在这里吗? => 是的。 执行它并停止往上搜索。
|
||||
|
@ -19,7 +19,7 @@ let duck = new Bird();
|
||||
duck.constructor
|
||||
```
|
||||
|
||||
但是 `duck` 和其他所有 `Bird` 的实例都应该表明它们是由 `Bird` 创建的,而不是由 `Animal` 创建的。 为此,你可以手动把 `Bird's` 的 constructor 属性设置为 `Bird` 对象:
|
||||
但是 `duck` 和其他所有 `Bird` 的实例都应该表明它们是由 `Bird` 创建的,而不是由 `Animal` 创建的。 为此,你可以手动将 `Bird` 的构造函数属性设置为 `Bird` 对象:
|
||||
|
||||
```js
|
||||
Bird.prototype.constructor = Bird;
|
||||
|
@ -12,7 +12,7 @@ dashedName: use-prototype-properties-to-reduce-duplicate-code
|
||||
|
||||
当只有两个实例时可能并不是什么问题,但想象一下如果有数百万个实例。 这将会产生许许多多重复的变量。
|
||||
|
||||
这里有一个更好的方法可以解决上述问题,那就是使用 `Bird’s` 的 `prototype`。 `prototype` 是一个可以在所有 `Bird` 实例之间共享的对象。 以下是一个在 `Bird prototype` 中添加 `numLegs` 属性的示例:
|
||||
更好的方法是使用 `Bird` 的 `prototype`。 `prototype` 是一个可以在所有 `Bird` 实例之间共享的对象。 以下是一个在 `Bird prototype` 中添加 `numLegs` 属性的示例:
|
||||
|
||||
```js
|
||||
Bird.prototype.numLegs = 2;
|
||||
@ -45,7 +45,7 @@ assert(beagle.numLegs !== undefined);
|
||||
assert(typeof beagle.numLegs === 'number');
|
||||
```
|
||||
|
||||
`numLegs` 应该是一个 `prototype` 属性而不是一个 `own` 属性。
|
||||
`numLegs` 应该是一个 `prototype` 属性,而不是一个自身属性。
|
||||
|
||||
```js
|
||||
assert(beagle.hasOwnProperty('numLegs') === false);
|
||||
|
@ -16,7 +16,7 @@ dashedName: create-a-controlled-form
|
||||
|
||||
我们增加了一个提交表单的按钮。 可以看到它的 `type` 被设置为 `submit`,表明它是控制表单提交的按钮。 在 `form` 中添加 `input` 元素,并像上个挑战一样设置其 `value` 和 `onChange()` 属性。 然后,应该完成 `handleSubmit` 方法,以便将组件 state 属性 `submit` 设置为本地 `state` 下的当前输入值。
|
||||
|
||||
**注意:** 还必须在提交处理程序中调用 `event.preventDefault()`,以防止默认的表单提交行为刷新网页。
|
||||
**注意:** 还必须在提交处理程序中调用 `event.preventDefault()`,以防止将会刷新网页的默认的表单提交行为。 为了便于学员操作,默认行为在这里被禁用,以防止重置挑战的代码。
|
||||
|
||||
最后,在 `form` 元素之后创建一个 `h1` 标签,该标签从组件的 `state` 渲染 `submit` 的值。 然后,可以在表单中键入任何内容,然后单击按钮(或按 enter 键),输入会渲染到页面上。
|
||||
|
||||
@ -98,7 +98,26 @@ assert(
|
||||
})();
|
||||
```
|
||||
|
||||
`h1` 标题应该从组件的 state 渲染 `submit` 字段的值。
|
||||
`handleSubmit` 应该调用 `event.preventDefault`。
|
||||
|
||||
```js
|
||||
const handleSubmit = MyForm.prototype.handleSubmit.toString();
|
||||
const allMatches = handleSubmit.match(/\bevent\.preventDefault\(\s*?\)/g) ?? [];
|
||||
const blockCommented = handleSubmit.match(
|
||||
/\/\*.*?\bevent\.preventDefault\(\s*?\).*?\*\//gs
|
||||
);
|
||||
const lineCommented = handleSubmit.match(
|
||||
/\/\/.*?\bevent\.preventDefault\(\s*?\)/g
|
||||
);
|
||||
const commentedMatches = [...(blockCommented ?? []), ...(lineCommented ?? [])];
|
||||
|
||||
assert(
|
||||
// At least one event.preventDefault() call exists and is not commented out
|
||||
allMatches.length > commentedMatches.length
|
||||
);
|
||||
```
|
||||
|
||||
`h1` 标头应该从组件的 state 渲染 `submit` 字段的值。
|
||||
|
||||
```js
|
||||
(() => {
|
||||
|
@ -18,8 +18,7 @@ dashedName: personal-library
|
||||
|
||||
# --instructions--
|
||||
|
||||
1. 将的 MongoDB 连接字符串添加到 `.env` 中(没有引号),`DB`
|
||||
示例: `DB=mongodb://admin:pass@1234.mlab.com:1234/fccpersonallib`
|
||||
1. 将你的 MongoDB 连接字符串添加到 `.env` 中,作为 `DB` 示例:`DB=mongodb://admin:pass@1234.mlab.com:1234/fccpersonallib`
|
||||
2. 在 `.env` 文件中设置 `NODE_ENV` 为 `test`中,没有引号
|
||||
3. 需要在 `routes/api.js` 中创建所有路由
|
||||
4. 在 `tests/2_functional-tests.js` 中创建所有的功能测试
|
||||
@ -66,7 +65,7 @@ async (getUserInput) => {
|
||||
let a = $.post(url, { title: 'Faux Book A' });
|
||||
let b = $.post(url, { title: 'Faux Book B' });
|
||||
let c = $.post(url, { title: 'Faux Book C' });
|
||||
Promise.all([a, b, c]).then(async () => {
|
||||
await Promise.all([a, b, c]).then(async () => {
|
||||
let data = await $.get(url);
|
||||
assert.isArray(data);
|
||||
assert.isAtLeast(data.length, 3);
|
||||
@ -214,8 +213,8 @@ async (getUserInput) => {
|
||||
|
||||
```js
|
||||
/**
|
||||
Backend challenges don't need solutions,
|
||||
because they would need to be tested against a full working project.
|
||||
Backend challenges don't need solutions,
|
||||
because they would need to be tested against a full working project.
|
||||
Please check our contributing guidelines to learn more.
|
||||
*/
|
||||
```
|
||||
|
Reference in New Issue
Block a user