+ 3
[javascript]Objects vs Classes
What are the differences between objects and classes and what are pros/cons.
3 Answers
+ 10
An object is something you create using a class.
class person {
constructor(name) {
this.name = name;
}
}
var Bert = new person('Bert');
This will create a new person object with the name property set to 'Bert'.
So a class is a constructor for an object.
+ 5
In javascript context, all is object, so in JS:
Advanced objects are created using a constructor function, and there is no classes concept at first, as JS object concept was based on prototype concept rather than class one.
Anyway, 'class' keyword was finally introduced in last specifications of ECMAScript 6 (on wich is based JS), but that's only a syntaxic sugar to bind and make use of class concept easier (but always using prototypes behind), and ECMAScript 6 is not yet fully supported by major browsers JS implementation ^^