Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

Difference between objects and classes in javascript?

creation and useability of objects and classes

user-image
Question ajoutée par Waqas Ahmed , Front-end developer , Netshore
Date de publication: 2013/10/08
Lokesh Gajbhiye
par Lokesh Gajbhiye , Software Programmer , Datacomp Web Technologies (India) Pvt. Ltd

Objects are basically an entities that does not contain any definition to it, while classes provides a definition to those and provide real meaning to it.eg for classes : Human,Vehicle eg for Objects  : Jhon, Joe belongs to human class otherwise we didn't knew whether johnmjoe are human or animalsimilary BMW,Jaguar are nothing but a vehicle that class defines to it. More precisely it can also be renamed as Cars reather vehicles. But here we used an generalised term.

irfan shaikh
par irfan shaikh , Consultant : Senior Web Designer/Front end Developer , Client : ● Impact Proximity, Dubai ● Cube Solution, Dubai ● WAC, Sharjha ● KIOEC, Kuwait ● IRIS Ltd.

In JavaScript, an object is data, with properties and methods. everything in javascript is object like string, number, array, date you can also define your own object llik :

car = new object(); or u can use the obejct literal like 

car={color:red, model: toyota,....etc} that define property inside "{}";

you can create the instance of object like 

mycar=new car(color, model, etc);

even though JS is oops language but not use classes & don't create object from classes instead it is prototype based. prototype allow you to add method & properties to object

 

Swathi Jayakumar
par Swathi Jayakumar , Software Developer , Sourcebits Technologies

Classes enclose a group of entities that share common properties or functions. Unlike C, C++ or JAVA, JS doesnot have a data type called "class", instead functions are used to define classes. 'this' pointer is used inside the function to define the data types and functions within the class. 

 

An object, however ,is an instance of a class, but the best part in JS is that its not necessary to define a class to define an object. If you need a single object, we can just define one object using var obj = {

} as a key-value pair, there is no need of defining an entire class. 

 

Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript

 

More Questions Like This