This question already has answers here:
Core difference between object oriented and object based language
(8 answers)
Closed 5 years ago.
What's the difference between object based and object oriented programming language?
Object oriented programming languages follow all concepts belonging to OOP. Object-based language doesn't support all the features of OOPs like Polymorphism and Inheritance Object-based language has in-built object like JavaScript has window object. Object-based languages are JavaScript.
Related
This question already has answers here:
Are ES6 classes just syntactic sugar for the prototypal pattern in Javascript?
(7 answers)
Closed 2 years ago.
Behind the scene, is the ES6 class based inheritance is exactly same as es5 prototypal inheritance or not?
If not, what is the difference?
Is chrome does the same as of ES6 tranpilers, i mean internally compile the es6 classes to function constructor?
Under the hood it's the same implementation, "class" in Javascript is just a syntactic sugar.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
JavaScript classes, introduced in ECMAScript 2015, are primarily syntactical sugar over JavaScript's existing prototype-based inheritance.
Browsers will treat it the same if it's supports ES6 class, otherwise your code written in class based inheritance will cause an error on the browser. So one of the difference you could consider is the browser support.
This question already has answers here:
Why is javascript the only client side scripting language implemented in browsers? [closed]
(3 answers)
Closed 7 years ago.
Every programming language has many alternatives, however, I could not find any alternative to javascript for accessing the DOM API? Why is this the case?
Thanks.
You have alternatives like Dart, LiveScript, Typescript, Babel and Coffeescript, yet these will be compiled/translated to native Javascript. The reason there is no real alternative is the fact that it is the only standard that is being implemented by all major browser "companies".
This question already has answers here:
Use of 'prototype' vs. 'this' in JavaScript?
(15 answers)
Closed 9 years ago.
I've been reading through JavaScript: The Good Parts and I'm currently on "Chapter 5: Inheritance."
From what I understand, using functional inheritance is preferred because it allows privacy for the properties and variables of an object while still allowing them to be called using methods outside of the object. However, it does seem like there is an advantage for prototypal inheritance because you can create a prototype object fairly easily (which makes understanding what the object is, to me, a little more concrete).
When should I choose one over the other? Should I always use functional inheritance whenever possible? Or are there "better" guidelines that I can follow to make that determination?
I've seen very little code that uses functional techniques as the primary form of inheritance. The vast majority I've seen uses prototypal inheritance. It's fast and easy to implement, and seems most natural to JavaScript.
That's not to say that functional inheritance should never be used, but I think you'll find prototypal more than sufficient for most applications.
Let's not also forget that you can still use some functional techniques within your prototypal inheritance, like giving each object it's own version of a function that closes over a variable in the constructor. So it doesn't need to entirely be one or the other.
Most important is to understand the concepts of prototypes and functions/closures. This alone will give you what you need to know in order to make appropriate decisions.
This question already has answers here:
How can implement overloading in JavaScript/jQuery?
(7 answers)
Closed 8 years ago.
I would like to understand if JavaScript really support Polymorphism ? With function arguments function overloading appears ok but function overriding in classical OO using inheritance ? Is it also supported by JavaScript
Any input pointers would be helpful.
JavaScript is an object oriented language, but not through classical OO. It supports it through prototyping. I would do some research of Java Script and prototyping - Start there
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Performing Inheritance in Javascript
What are the ways to implement inheritance in JavaScript Which one is the best and why?
I can think of only one: prototyping, with which you can do polymorphism, a bit of encapsulation and inheritance. That's the only way inheritance* is supported by JavaScript, but quite successfully and to quite a deep extend. See this nice and easy read on OO in JavaScript.
An excellent read, too, is Object Oriented JavaScript by Stoyan Stefanov, I can highly recommend it to you, your JS will never look the same again.
* EDIT: this is a special type of OO: prototype based programming, and JS supports it well, but as commented by Adam, you can trick your way through if you want to do it differently (advice: don't).
Doug Crockford lists several mechanisms for inheritance in his "Javascript: The Good Parts". I'd recommend reading that for a deep understanding. The material might also be available on line.
Since JavaScript is a class-free, object-oriented language, it uses prototypal inheritance. Read Douglas Crockford's "Prototypal Inheritance in JavaScript" to learn why: http://javascript.crockford.com/prototypal.html