translate Object Oriented Programming - 100%#61
Open
XiaoLuo01 wants to merge 2 commits intoFreeCodeCampChina:translatefrom
Open
translate Object Oriented Programming - 100%#61XiaoLuo01 wants to merge 2 commits intoFreeCodeCampChina:translatefrom
XiaoLuo01 wants to merge 2 commits intoFreeCodeCampChina:translatefrom
Conversation
huluoyang
suggested changes
Aug 8, 2018
| "<blockquote>console.log(duck.constructor)<br>// prints ‘undefined’ - Oops!</blockquote>", | ||
| "To fix this, whenever a prototype is manually set to a new object, remember to define the <code>constructor</code> property:", | ||
| "<blockquote>Bird.prototype = {<br> constructor: Bird, // define the constructor property<br> numLegs: 2,<br> eat: function() {<br> console.log(\"nom nom nom\");<br> },<br> describe: function() {<br> console.log(\"My name is \" + this.name); <br> }<br>};</blockquote>", | ||
| "如果我们手动的给一个新对象重新设置<code>原型</code>的话,这将会产生一个重要的副作用:删除了<code>constructor</code>属性!所以在上一个挑战中,我们将<code>duck</code>的<code>constructor</code>属性输出到控制台的话将会得到以下结果:", |
Contributor
There was a problem hiding this comment.
一句话2个的,你懂的。
整个段落的翻译很生硬,不流畅。
重点把握好:It erased the constructor property
| "<blockquote>Bird.prototype = {<br> constructor: Bird, // define the constructor property<br> numLegs: 2,<br> eat: function() {<br> console.log(\"nom nom nom\");<br> },<br> describe: function() {<br> console.log(\"My name is \" + this.name); <br> }<br>};</blockquote>", | ||
| "如果我们手动的给一个新对象重新设置<code>原型</code>的话,这将会产生一个重要的副作用:删除了<code>constructor</code>属性!所以在上一个挑战中,我们将<code>duck</code>的<code>constructor</code>属性输出到控制台的话将会得到以下结果:", | ||
| "<blockquote>console.log(duck.constructor)<br>// 哎呀,控制台中输出了 ‘undefined’!</blockquote>", | ||
| "为了解决这个问题,所以凡是原型被手动设置给了一个新对象,都要记得重新定义一个<code>constructor</code>属性:", |
| "title": "Understand Where an Object’s Prototype Comes From", | ||
| "description": [ | ||
| "Just like people inherit genes from their parents, an object inherits its <code>prototype</code> directly from the constructor function that created it. For example, here the <code>Bird</code> constructor creates the <code>duck</code> object:", | ||
| "就像人们从父母那里继承基因一样,对象也可直接从创建它的构造函数那里继承其<code>原型。请看下面的例子:<code>Bird</code>构造函数创建了一个<code>duck</code>对象:", |
Contributor
There was a problem hiding this comment.
此处的 code 缺少闭合标签,而且 code 里面的应该保持原文输出。
| "<blockquote>function Bird(name) {<br> this.name = name;<br>}<br><br>let duck = new Bird(\"Donald\");</blockquote>", | ||
| "<code>duck</code> inherits its <code>prototype</code> from the <code>Bird</code> constructor function. You can show this relationship with the <code>isPrototypeOf</code> method:", | ||
| "<blockquote>Bird.prototype.isPrototypeOf(duck);<br>// returns true</blockquote>", | ||
| "<code>duck</code>对象继承了<code>Bird</code>构造函数的<code>原型</code>。你可以使用<code>isPrototypeOf</code>方法来验证他们原型之间的关系:", |
Contributor
There was a problem hiding this comment.
duck从Bird构造函数那里继承了它的prototype,你可以使用isPrototypeOf方法来验证他们之间的关系:
| "<blockquote>Bird.prototype.isPrototypeOf(duck);<br>// 返回 true</blockquote>", | ||
| "<hr>", | ||
| "Use <code>isPrototypeOf</code> to check the <code>prototype</code> of <code>beagle</code>." | ||
| "使用<code>isPrototypeOf</code>方法验证<code>beagle</code>的<code>原型</code>是否继承了<code>Bird</code>构造函数的<code>原型</code>。" |
| { | ||
| "text": "Your code should declare a <code>glideMixin</code> variable that is a function.", | ||
| "testString": "assert(typeof glideMixin === \"function\", 'Your code should declare a <code>glideMixin</code> variable that is a function.');" | ||
| "text": "你的代码应该声明一个变量名为<code>glideMixin</code>的函数。", |
Contributor
There was a problem hiding this comment.
你的代码应该声明一个变量名为glideMixin的函数。 => 啰嗦
你应该声明一个变量名为glideMixin的函数。=> 简洁
这个问题全文都有,请自行斟酌后修改。
| "The simplest way to make properties private is by creating a variable within the constructor function. This changes the scope of that variable to be within the constructor function versus available globally. This way, the property can only be accessed and changed by methods also within the constructor function.", | ||
| "<blockquote>function Bird() {<br> let hatchedEgg = 10; // private property<br><br> this.getHatchedEggCount = function() { // publicly available method that a bird object can use<br> return hatchedEgg;<br> };<br>}<br>let ducky = new Bird();<br>ducky.getHatchedEggCount(); // returns 10</blockquote>", | ||
| "Here <code>getHachedEggCount</code> is a privileged method, because it has access to the private variable <code>hatchedEgg</code>. This is possible because <code>hatchedEgg</code> is declared in the same context as <code>getHachedEggCount</code>. In JavaScript, a function always has access to the context in which it was created. This is called <code>closure</code>.", | ||
| "因此,你代码的任何部分都可以轻松地将<code>bird</code>的 name 属性更改为任意值。想想密码和银行账户之类的东西,如果你代码库的任何部分都可以轻易改变,那么将会引起很多问题。", |
| # 面向对象编程挑战简介 # | ||
|
|
||
| At its core, software development solves a problem or achieves a result with computation. The software development process first defines a problem, then presents a solution. Object oriented programming is one of several major approaches to the software development process. | ||
| 软件开发的核心是通过计算解决问题或取得结果。软件开发过程首先定义问题,然后提出解决方案。面向对象编程是软件开发过程的几种主要方法之一。 |
Contributor
There was a problem hiding this comment.
这是我直接从有道翻译的结果,你对比下:
软件开发的核心是解决问题或通过计算获得结果。软件开发过程首先定义一个问题,然后提出一个解决方案。面向对象编程是软件开发过程的几种主要方法之一。
| 顾名思义,面向对象编程将代码组织成对象定义。这些有时被称为类,它们将数据和相关行为组合在一起。数据是对象的属性,行为(或函数)是方法。 | ||
|
|
||
| The object structure makes it flexible within a program. Objects can transfer information by calling and passing data to another object's methods. Also, new classes can receive, or inherit, all the features from a base or parent class. This helps to reduce repeated code. | ||
| 对象结构使它在程序中变得灵活。对象可以通过调用数据并将数据传递给另一个对象的方法来传递信息。此外,新类可以从基类或父类接收或继承所有功能。这有助于减少重复代码。 |
| 对象结构使它在程序中变得灵活。对象可以通过调用数据并将数据传递给另一个对象的方法来传递信息。此外,新类可以从基类或父类接收或继承所有功能。这有助于减少重复代码。 | ||
|
|
||
| Your choice of programming approach depends on a few factors. These include the type of problem, as well as how you want to structure your data and algorithms. This section covers object oriented programming principles in JavaScript. | ||
| 你对编程方法的选择取决于几个因素。这些包括问题的类型,以及如何构造数据和算法。本节将介绍 JavaScript 中面向对象的编程原则。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Translate Object Oriented Programming comlete