View Full Version : Does JavaScript Support OOPs?

05-25-2012, 06:44 AM
I have heard from many and have read a lot that JS does not support OOPs. Then how come mootools (http://mootools.net/) claim that their framework supports Object-Oriented JavaScript ?

Someone Pls throw some light on this.

Old Pedant
05-25-2012, 07:13 AM
Depends on how you define OOPS. Where the "S" (System) gets the most emphasis.

I would say that JavaScript is one of the few *TRUE* Object Oriented Programming Languages in existence. Truly, the Object is the basis of everything in JS!

JavaScript is *NOT* a Class Oriented Programming Language. It doesn't support the whole concept of classes. (Yes, I know, readers: There are ways to make JS behave AS IF it had classes. Sorry, but it is still not "Class Oriented".)

And many books that talk about OOPS expect that the language in use does support classes and all that goes with them.

It's interesting (to me): At one point in my life I was working on a team that created a combined Java and C++ programming system. You really could code one class in Java and another in C++ and they would automatically be aware of each other. You could even have a base class in C++ with a derived class in Java and then a class derived from the Java class back in C++. Wonderful system. *sigh* ANYWAY...we discussed for a long time adding truly dynamic *OBJECTS* to both C++ and Java in that system! In other words, just as you can do in JavaScript, you could have AT RUNTIME added methods and properties to an individual object without modifying the class it was an instance of. Now *THAT* would have been an OOPS in any meaning of the term that you want to apply.

Old Pedant
05-25-2012, 07:34 AM
The argument about the definitions of all of these terms has been going on for more than 20 years. I don't expect it to end soon.

A long time ago, I started calling Java/C++/C#/et al. "class oriented" just to be able to distinguish them from "object oriented". But iBall's definitions are shared by just as many as those who might agree with me. And then there will also just as many (or probably more) who won't agree with either of us.

Old Pedant
05-25-2012, 07:44 AM
But you forgot the ones who agree with both of us! And mostly you forgot the 99.7% who either have never heard of OOPS or who don't give rat's patootie. <grin/>

Old Pedant
05-25-2012, 07:57 AM
Ah, no...YOU assumed that the options given constituded the universal set!

Read again (with added parenthetical content <grin/>):

But iBall's definitions are shared by just as many [2 people] as those who might agree with me [2 people]. And then there will also just as many (or probably more) [397 people] who won't agree with either of us.
The only "absolute" number in there is the number of people who agree with me. And since I can only definitively name two other persons who use the same terms I do...

[Well, I think there are more than 2, but I can't prove it. <grin/>]

Philip M
05-25-2012, 08:30 AM
The great advantage of being on iBall's ignore list is that he cannot seize on something in one of my posts to start a pointless and belligerent argument. :)

05-25-2012, 08:31 AM
I see javascript as Object Based as opposed to Object Orientated given that OOP = Object Orientated Programming

just for my information, how do you define "Object Based" and "Object Oriented"?

personally, I go along the definition given in Wikipedia:

Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs.

05-25-2012, 08:58 AM
Object Based to me means it has functionality similar to, but not including all the concepts and functionality behind a programming object.
that leads to the question: what are all those concepts?

again, I would go along the definitions mentioned by Wikipedia:

Fundamental features and concepts
Similarly, in his 2003 book, Concepts in programming languages, John C. Mitchell identifies four main features: dynamic dispatch, abstraction, subtype polymorphism, and inheritance. Michael Lee Scott in Programming Language Pragmatics considers only encapsulation, inheritance and dynamic dispatch
all those mentioned concepts are fulfilled in JS.

05-25-2012, 09:10 AM
JavaScript is a prototyping language - since OOP is a subset of what a prototyping language can do you can of course use OOP with JavaScript but it can result in the code being longer and more convoluted than it might be if you were to use the full power of the language.

05-25-2012, 09:10 AM
I just wanted to know your definitions, because this whole discussion is all about them (and that’s why it goes on since 20+ years). (I am aware that we will never have matching definitions of OOP)

05-25-2012, 09:25 AM
the only problem with that is that

all the concepts and functionality behind a programming object
are not (necessarily) known to me, as I am not a professional programmer. (ok, a citation would suffice)