mozilla

Compare Revisions

More Flexible Constructors

Change Revisions

Revision 117594:

Revision 117594 by Dria on

Revision 117595:

Revision 117595 by Johndr on

Title:
More Flexible Constructors
More Flexible Constructors
Slug:
JavaScript/Guide/Obsolete_Pages/The_Employee_Example/More_Flexible_Constructors
JavaScript/Guide/Obsolete_Pages/The_Employee_Example/More_Flexible_Constructors
Content:

Revision 117594
Revision 117595
n35this.name = name || "";n35  this.name = name || "";
36this.dept = dept || "general";36  this.dept = dept || "general";
n154this.base = WorkerBee;n154  this.base = WorkerBee;
155this.base(name, "engineering", projs);155  this.base(name, "engineering", projs);
156this.machine = mach || "";156  this.machine = mach || "";
n195this.base = WorkerBee;n195  this.base = WorkerBee;
196this.base(name, "engineering", projs);196  this.base(name, "engineering", projs);
197this.machine = mach || "";197  this.machine = mach || "";
n207this.base = WorkerBee;n207  this.base = WorkerBee;
208this.base(name, "engineering", projs);208  this.base(name, "engineering", projs);
209this.machine = mach || "";209  this.machine = mach || "";
tt217    </p>
218    <hr>
219    <p>
220      Another way of inheriting is by using the .call/.apply meth
 >ods. Below are equivalent:
221    </p>
222    <table>
223      <tbody>
224        <tr>
225          <td>
226            <pre class="eval">
227function Engineer (name, projs, mach) {
228  this.base = WorkerBee;
229  this.base(name, "engineering", projs);
230  this.machine = mach || "";
231}
232</pre>
233          </td>
234          <td>
235            <pre class="eval">
236function Engineer (name, projs, mach) {
237  WorkerBee.call(this, name, "engineering", projs);
238  this.machine = mach || "";
239}
240</pre>
241          </td>
242        </tr>
243      </tbody>
244    </table>
245    <p>
246      Using the javascript .call method makes a cleaner implement
 >ation because the ".base" is not needed anymore.

Back to History