The Class
JavaScript is basically prototype-based language which have no class statement,
as found in C++ or Java. This is actually confusing for programmers
accustomed to languages with a class statement. In reality, JavaScript uses
functions as classes. Defining a class is as easy as defining a function.
Examples:
function employee() { }
The Objects
Objects are basically instance of classes which help us to access the methods
of that class.
To create a new instance of an object obj we use the statement new obj,
assigning the result (which will be type obj) to a variable to access it later.
In the example below we define a class named employee and we
create two instances (emp1 and emp2).
function employee() { }
var emp1= new employee();
var emp2= new employee();
JavaScript is basically prototype-based language which have no class statement,
as found in C++ or Java. This is actually confusing for programmers
accustomed to languages with a class statement. In reality, JavaScript uses
functions as classes. Defining a class is as easy as defining a function.
Examples:
function employee() { }
The Objects
Objects are basically instance of classes which help us to access the methods
of that class.
To create a new instance of an object obj we use the statement new obj,
assigning the result (which will be type obj) to a variable to access it later.
In the example below we define a class named employee and we
create two instances (emp1 and emp2).
function employee() { }
var emp1= new employee();
var emp2= new employee();
No comments:
Post a Comment