aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/operators/new/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/javascript/reference/operators/new/index.html')
-rw-r--r--files/zh-cn/web/javascript/reference/operators/new/index.html20
1 files changed, 10 insertions, 10 deletions
diff --git a/files/zh-cn/web/javascript/reference/operators/new/index.html b/files/zh-cn/web/javascript/reference/operators/new/index.html
index 0b2d5c24c7..e6833d4cc7 100644
--- a/files/zh-cn/web/javascript/reference/operators/new/index.html
+++ b/files/zh-cn/web/javascript/reference/operators/new/index.html
@@ -19,7 +19,7 @@ translation_of: Web/JavaScript/Reference/Operators/new
<h2 id="语法">语法</h2>
-<pre class="syntaxbox notranslate">new <em>constructor</em>[([<em>arguments</em>])]</pre>
+<pre class="syntaxbox">new <em>constructor</em>[([<em>arguments</em>])]</pre>
<h3 id="参数">参数</h3>
@@ -67,7 +67,7 @@ translation_of: Web/JavaScript/Reference/Operators/new
<p>你可以使用 <code><a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/prototype">Function.prototype</a></code> 属性将共享属性添加到以前定义的对象类型。这定义了一个由该函数创建的所有对象共享的属性,而不仅仅是对象类型的其中一个实例。下面的代码将一个值为 <code>null</code> 的 <code>color</code> 属性添加到 <code>car</code> 类型的所有对象,然后仅在实例对象 <code>car1</code> 中用字符串 "<code>black</code>" 覆盖该值。详见 <a href="/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Function/prototype">prototype</a>。</p>
-<pre class="brush: js notranslate">function Car() {}
+<pre class="brush: js">function Car() {}
car1 = new Car();
car2 = new Car();
@@ -95,7 +95,7 @@ console.log(car2.color) // original color
<p>假设你要创建一个汽车的对象类型。你希望这个类型叫做car,这个类型具备make, model, year等属性,要做到这些,你需要写这样一个函数:</p>
-<pre class="brush: js notranslate">function Car(make, model, year) {
+<pre class="brush: js">function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
@@ -104,19 +104,19 @@ console.log(car2.color) // original color
<p>现在,你可以如下所示创建一个 <code>mycar</code> 的对象:</p>
-<pre class="brush: js notranslate">var mycar = new Car("Eagle", "Talon TSi", 1993);</pre>
+<pre class="brush: js">var mycar = new Car("Eagle", "Talon TSi", 1993);</pre>
<p>这段代码创建了 <code>mycar</code> 并给他的属性指定值,于是 <code>mycar.make</code> 的值为"<code>Eagle</code>", <code>mycar.year</code> 的值为1993,以此类推。</p>
<p>你可以通过调用 <code>new</code> 来创建任意个汽车对象。例如:</p>
-<pre class="brush: js notranslate">var kenscar = new Car("Nissan", "300ZX", 1992);</pre>
+<pre class="brush: js">var kenscar = new Car("Nissan", "300ZX", 1992);</pre>
<h3 id="对象属性为其他对象">对象属性为其他对象</h3>
<p>假设你定义了一个对象叫做 <code>person</code>:</p>
-<pre class="brush: js notranslate">function Person(name, age, sex) {
+<pre class="brush: js">function Person(name, age, sex) {
this.name = name;
this.age = age;
this.sex = sex;
@@ -125,13 +125,13 @@ console.log(car2.color) // original color
<p>然后实例化两个新的 <code>person</code> 对象如下:</p>
-<pre class="brush: js notranslate">var rand = new Person("Rand McNally", 33, "M");
+<pre class="brush: js">var rand = new Person("Rand McNally", 33, "M");
var ken = new Person("Ken Jones", 39, "M");
</pre>
<p>然后你可以重写 <code>car</code> 的定义,添加一个值为 <code>person</code> 对象的 <code>owner</code> 属性,如下:</p>
-<pre class="brush: js notranslate">function Car(make, model, year, owner) {
+<pre class="brush: js">function Car(make, model, year, owner) {
this.make = make;
this.model = model;
this.year = year;
@@ -141,13 +141,13 @@ var ken = new Person("Ken Jones", 39, "M");
<p>为了实例化新的对象,你可以用如下代码:</p>
-<pre class="brush: js notranslate">var car1 = new Car("Eagle", "Talon TSi", 1993, rand);
+<pre class="brush: js">var car1 = new Car("Eagle", "Talon TSi", 1993, rand);
var car2 = new Car("Nissan", "300ZX", 1992, ken);
</pre>
<p>创建对象时,并没有传字符串或数字给owner,而是传了对象 <code>rand</code> 和 <code>ken</code> 。这个时候,你可以这样来获取 <code>car2</code> 的owner的name:</p>
-<pre class="brush: js notranslate">car2.owner.name</pre>
+<pre class="brush: js">car2.owner.name</pre>
<h2 id="规范">规范</h2>