ES6: Use class Syntax to Define a Constructor Function

ES6 provides a new syntax to help create objects, using the keyword class.

This is to be noted, that the classsyntax 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 newkeyword to instantiate an object.

var SpaceShuttle = function(targetPlanet){
this.targetPlanet = targetPlanet;
var zeus = new SpaceShuttle('Jupiter');

The class syntax simply replaces the constructor function creation:

class SpaceShuttle {
this.targetPlanet = targetPlanet;
const zeus = new SpaceShuttle('Jupiter');

Notice that the classkeyword declares a new function, and a constructor was added, which would be invoked when newis called – to create a new object.

Use classkeyword and write a proper constructor to create the Vegetableclass.

The Vegetablelets you create a vegetable object, with a property name, to be passed to constructor.


function makeClass() {

"use strict";
 /* Alter code below this line */
 class Vegetable {
 /* Alter code above this line */
 return Vegetable;
const Vegetable = makeClass();
const carrot = new Vegetable('carrot');
console.log(carrot.name); // => should be 'carrot'

Definition – What does Web Programming mean?

Web programming refers to the writing, markup and coding involved in Web development, which includes Web content, Web client and server scripting and network security. The most common languages used for Web programming are XML, HTML, JavaScript, CSS and PHP. Web programming is different from just programming, which requires interdisciplinary knowledge on the application area, client and server scripting, and database technology.

At some point most web developers will be in the position of having to either provide hosting for their clients’ websites, or they will need to know which web hosts to recommend to their clients. Web hosting services store and activate all the files your website needs in order to function and to be active. Some of the best web hosting companies are: HostGator, GoDaddy, Bluehost, iPage, InMotion Hosting, HostFav, DreamHost, Interserver, Namecheap, 1 & 1, Fasthosts, Hostinger, GreenGeeks, Justhost, SiteGround, Host1Plus, eUKhost, Arvixe, FatCow, HostMonster and more.

Web Programming Degree

If you have a passion for connecting people through technology, our online Web Programming degree will provide you with in-demand skills to do so in a growing industry. In our program, you’ll become proficient in Java, Microsoft Azure, Google Developers Training, Web development and cloud computing—all of which help you prepare for various types of web programming roles, such as web developer, front-end developer, back-end developer or web app developer.

Through online Web Development courses, you’ll build your own professional portfolio for your future employers.


Leave a Reply

Your email address will not be published. Required fields are marked *



33 − 28 =