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

Update Web/JavaScript/Guide/Details_of_the_Object_Model #4762

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ <h4 id="JavaScript_using_this_may_cause_an_error_for_the_following_examples">Jav
this.dept = 'general';
}
}

</pre>

<h4 id="JavaScript_**_use_this_instead">JavaScript ** (use this instead)</h4>
Expand All @@ -140,7 +139,6 @@ <h4 id="JavaScript_**_use_this_instead">JavaScript ** (use this instead)</h4>
this.name = '';
this.dept = 'general';
}

</pre>

<h4 id="Java">Java</h4>
Expand Down Expand Up @@ -180,7 +178,6 @@ <h4 id="Java_2">Java</h4>
public class WorkerBee extends Employee {
public String[] projects = new String[0];
}

</pre>

<p>The <code>Engineer</code> and <code>SalesPerson</code> definitions create objects that descend from <code>WorkerBee</code> and hence from <code>Employee</code>. An object of these types has properties of all the objects above it in the chain. In addition, these definitions override the inherited value of the <code>dept</code> property with new values specific to these objects.</p>
Expand Down Expand Up @@ -215,7 +212,6 @@ <h4 id="Java_3">Java</h4>
public String dept = "engineering";
public String machine = "";
}

</pre>

<p>Using these definitions, you can create instances of these objects that get the default values for their properties. The next figure illustrates using these JavaScript definitions to create new objects and shows the property values for the new objects.</p>
Expand Down Expand Up @@ -310,15 +306,19 @@ <h3 id="Adding_properties">Adding properties</h3>

<p>As soon as JavaScript executes this statement, the <code>mark</code> object also has the <code>specialty</code> property with the value of <code>"none"</code>. The following figure shows the effect of adding this property to the <code>Employee</code> prototype and then overriding it for the <code>Engineer</code> prototype.</p>

<p><img alt="" class="internal" src="figure8.4.png"><br>
<small><strong>Adding properties</strong></small></p>
<figure>
<img alt="" class="internal" src="figure8.4.png">
<figcaption>Adding properties</figcaption>
</figure>

<h2 id="More_flexible_constructors">More flexible constructors</h2>

<p>The constructor functions shown so far do not let you specify property values when you create an instance. As with Java, you can provide arguments to constructors to initialize property values for instances. The following figure shows one way to do this.</p>

<p><img alt="" class="internal" src="figure8.5.png"><br>
<small><strong>Specifying properties in a constructor, take 1</strong></small></p>
<figure>
<img alt="" class="internal" src="figure8.5.png">
<figcaption>Specifying properties in a constructor, take 1</figcaption>
</figure>

<p>The following pairs of examples show the Java and JavaScript definitions for these objects.</p>

Expand Down Expand Up @@ -410,8 +410,10 @@ <h2 id="More_flexible_constructors">More flexible constructors</h2>

<p>So far, the constructor function has created a generic object and then specified local properties and values for the new object. You can have the constructor add more properties by directly calling the constructor function for an object higher in the prototype chain. The following figure shows these new definitions.</p>

<p><img alt="" class="internal" src="figure8.6.png"><br>
<small><strong>Specifying properties in a constructor, take 2</strong></small></p>
<figure>
<img alt="" class="internal" src="figure8.6.png">
<figcaption>Specifying properties in a constructor, take 2</figcaption>
</figure>

<p>Let's look at one of these definitions in detail. Here's the new definition for the <code>Engineer</code> constructor:</p>

Expand Down