Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1 js/04 object basics/06 constructor new #124

Conversation

sunhaokk
Copy link
Contributor

#28
翻译完毕

@Tivcrmn
Copy link

Tivcrmn commented Jul 3, 2018

@leviding 校对认领

@leviding
Copy link
Member

leviding commented Jul 3, 2018

@Tivcrmn ok

Copy link

@Tivcrmn Tivcrmn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sunhaokk @leviding 校对完成

@@ -60,96 +60,96 @@ let user = {
};
```

Now if we want to create other users, we can call `new User("Ann")`, `new User("Alice")` and so on. Much shorter than using literals every time, and also easy to read.
现在,如果我们想创建其他用户,我们可以调用 `new User("Ann")``new User("Alice")` 等等。比每次使用文字要短得多,而且易于阅读。
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

『比每次使用文字要短得多』=>『比每次使用字面量创建要短得多』


Let's note once again -- technically, any function can be used as a constructor. That is: any function can be run with `new`, and it will execute the algorithm above. The "capital letter first" is a common agreement, to make it clear that a function is to be run with `new`.
让我们再次注意 -- 从技术上讲,任何函数都可以用作构造函数。即:任何函数都可以运行 `new`,它会执行上面的算法。 “首字母大写”是一个共同的约定,以明确表示一个函数将被运行 `new`
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

『以明确表示一个函数将被运行 new,』=>『以明确表示一个函数将被使用 new运行,』

}

alert( new BigUser().name ); // Godzilla, got that object ^^
alert( new BigUser().name ); // 哇哦,得到了 object ^^
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

『哇哦,得到了 object ^^』=>『哇哦,得到了对象,name 属性值为 Godzilla』


Of course, we can add to `this` not only properties, but methods as well.
当然,我们不仅可以将 this 添加到属性中,而且还添加到方法中。
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

『我们不仅可以将 this 添加到属性中,而且还添加到方法中。』=>『我们不仅可以将属性添加到 this 中,而且还可以添加方法。』


We can use constructor functions to make multiple similar objects.
- 构造函数只能使用 `new` 来调用。这样的调用意味着在开始时创建空的 `this`,并在最后返回填充的。
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

『填充的』=>『填充的对象』


```smart header="Objects, we'll be back!"
In this chapter we only cover the basics about objects and constructors. They are essential for learning more about data types and functions in the next chapters.
在本章中,我们只介绍关于对象和构造函数的基础知识。它们对于在下一章中更多地了解数据类型和功能非常重要。
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

『数据类型和功能』=>『数据类型和函数』

@leviding leviding added the WIP Work in process label Jul 4, 2018
Copy link
Member

@leviding leviding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

很赞

@leviding
Copy link
Member

@sunhaokk 格式上已经没什么问题了,很赞。

@leviding leviding merged commit 78676fa into javascript-tutorial:zh-hans Jul 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants