I want to know what is the core difference between
Object Oriented and Object based languages
I have read many post all of them are saying two things
Object-oriented language supports all the features of OOPs and Object-based language doesn't support all the features of OOPs like Polymorphism and Inheritance.
They are giving example of javascript as object based and java as object oriented
Like this post of stackoverflow
Difference between object oriented and object based language
But I want to know what is the core difference between both the concept regardless of any language.
Got the answer
Finally got the thing
thanks to Matías Fidemraizer
Answer which is not dependent on any language, not dependent on any feature, the core differnce for which I am loooking that is
The language which itself contains objects is called as object based language and the language with follows object oriented concepts is known as object oriented language
JavaScript is a prototype-oriented language.
It can build actual objects from a constructor function and it has almost any feature that any object could have:
In JavaScript, any object has a prototype, including functions. The prototype itself is a rudimentary way of adding object members to any newly created instance of the whole object.
var constructor = function() { };
constructor.prototype.text = "hello world";
alert(new constructor().text); // This alerts hello world
Why JavaScript isn't an object-oriented programming (scripting) language? Because it has no feature that fits the requirements of the definition of object-oriented programming:
Perhaps I forgot to mention some other detail, but I honestly believe that this is a good summary.
The core difference is an object-oriented programming language has the features that an object-oriented paradigm must have in order to be considered an object-oriented programming language. Thus, JavaScript, for now, isn't an actual object-oriented programming language because it lacks actual polymorphism and inheritance.
Esthetically speaking yes, ES2015 and above has a major improvement that let consider a not fully but more closer to an object-oriented programming: syntactic sugar to call to the super class.
For example:
class A {
doStuff() {
console.log("hello world");
}
}
class B extends A {
doStuff() {
super.doStuff();
console.log("...and goodbye!");
}
}
This is polymorphism. A more specialized class can override its base class to both completely change a function behavior or do what the base was already doing, adding new code to the function.
BTW, ES2015 and above still lacks true encapsulation: where are access modifiers like private
or public
here? Nowhere.
And, at the end of the day, ES2015 and above implement class-based OOP but it's still a syntactic sugar layer on top of ECMAScript 5.x... The above code still works with prototypes under the hoods and it works the same way as if you would code it in ECMAScript 5.x:
function A() {
}
A.prototype.doStuff = function() {
console.log("hello world");
};
function B() {
}
B.prototype = Object.create(A.prototype);
B.prototype.doStuff = function() {
A.prototype.doStuff.call(this);
console.log("...and goodbye!");
};
Let's hope I'll need to update this answer again because ES2020 has already proposed access modifiers and we'll be able to consider JavaScript another language which fully-supports object-oriented programming!