PDA

View Full Version : Is JavaScript an OOP?



matthewbluewars
04-13-2008, 02:50 PM
For those of your unfamiliar, OOP is Object Oriented Programming. There has been a long debate on whether JavaScript is one.
I would like to have a debate in this thread about it. In my personal opinion, JavaScript IS an OOP because it is impossible to use it without objects.

boogyman
04-13-2008, 06:14 PM
Java is an OOP, but Javascript is not by default. It is possible to create and use Javascript Objects.

djr33
04-13-2008, 06:30 PM
If I can, by choice, speak Russian, does that mean that I am Russian?

I think that basically summarizes the argument.

BYK
04-13-2008, 06:51 PM
It has strong OOP abilities with prototype support. Don't you think it is Russian, djr33? :)

Trinithis
04-13-2008, 06:54 PM
JS has OO support. It just doesn't have classes, but classes are not requirements for OOP anyway.

Looking at wikipedia's requirements for an OOPL:


Class: Whoever tells you this is a requirement for a language to be OO is lying. In any case, in JS, you can (and usually do) simulate classes.
Object: Objects exist in JS.
Method: In JS, a method is any function that is bound to an object when called.
Message Passing: Function arguments and state changes.
Inheritance: Prototype chain and call/apply.
Encapsulation: Closures can be used to encapsulate, but we generally don't bother (at least with constructor functions).
Abstraction: JS has all the wikipedia elements under Abstraction.
Polymorphism: Duck-typing.


JS supports all of these.

matthewbluewars
04-22-2008, 12:45 AM
I think DHTML, not the JavaScript itself is OOP because it is nearly impossible to do something useful with the data without objects. Alert(), the simplist task, is acually part of the window object. So is getElementById().