I somewhat understand the difference between Javascript and Java when it comes to OOP. I read the bottom paragraph in the Javascript book that I have but I don’t fully understand what it mean, can you further explain and provide examples to show the difference between the two languages?
“In many object-oriented programming languages, it is possible to define a class of objects and then create individual objects that are instances of that class.”
Thanks!
Object oriented javascript is very simple.
You create an object.
And then you create an instance of that object through prototypical inheritance
This is different from classical OO because any object can be a “class” in javascript. and there is only one inheritance chain, the chain of prototypes.
Normally in classical OO languages the classes would inherit from each other and the instances would have a seperate chain of inheritance.
Also in classical OO you have two objects, the actual class object and the blueprint for the instance (i.e.
static). This doesn’t exist in javascript because there is only one object, the blueprint.Disclaimer:
Object.createis ES5, so you need an es5-shim for legacy platforms.