Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.
creation and useability of objects and classes
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.
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
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