ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Difference between objects and classes in javascript?

creation and useability of objects and classes

user-image
تم إضافة السؤال من قبل Waqas Ahmed , Front-end developer , Netshore
تاريخ النشر: 2013/10/08
Lokesh Gajbhiye
من قبل 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
من قبل 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
من قبل 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

 

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟