Thursday, March 13, 2014

creating the function and creating the instance of the function:

The Class in JavaScript

Unlike Java, C++ etc, JavaScript does not contains class statement. JavaScript is a prototype-based language. JavaScript uses functions as classes. Defining a class is as easy as defining a function. In the example below we define a new class called Car.
//Define the class Car
function Car() { }

The Object (Class Instance) in JavaScript

For creating instances of any class i.e. objects use new keyword. For example, in below code snippet we created two instances of class Car.
//Define the class Car
function Car() { }
 
var car1 = new Car();
var car2 = new Car();

No comments:

Post a Comment