parent
f52ccf54f5
commit
9e840de396
|
@ -1067,9 +1067,9 @@
|
|||
"ES6 provides a new syntax to help create objects, using the keyword <dfn>class</dfn>.",
|
||||
"This is to be noted, that the <code>class</code> syntax is just a syntax, and not a full-fledged class based implementation of object oriented paradigm, unlike in languages like Java, or Python, or Ruby etc.",
|
||||
"In ES5, we usually define a constructor function, and use the <code>new</code> keyword to instantiate an object.",
|
||||
"<blockquote>var SpaceShuttle = function(targetPlanet){<br> this.targetPlanet = targetPlanet;<br>}<br>var zeus = new spaceShuttle('Jupiter');</blockquote>",
|
||||
"<blockquote>var SpaceShuttle = function(targetPlanet){<br> this.targetPlanet = targetPlanet;<br>}<br>var zeus = new SpaceShuttle('Jupiter');</blockquote>",
|
||||
"The class syntax simply replaces the constructor function creation:",
|
||||
"<blockquote>class SpaceShuttle {<br> constructor(targetPlanet){<br> this.targetPlanet = targetPlanet;<br> }<br>}<br>const zeus = new spaceShuttle('Jupiter');</blockquote>",
|
||||
"<blockquote>class SpaceShuttle {<br> constructor(targetPlanet){<br> this.targetPlanet = targetPlanet;<br> }<br>}<br>const zeus = new SpaceShuttle('Jupiter');</blockquote>",
|
||||
"Notice that the <code>class</code> keyword declares a new function, and a constructor was added, which would be invoked when <code>new</code> is called - to create a new object.",
|
||||
"<hr>",
|
||||
"Use <code>class</code> keyword and write a proper constructor to create the <code>Vegetable</code> class.",
|
||||
|
|
Loading…
Reference in New Issue