*
The moose likes HTML, CSS and JavaScript and the fly likes JavaScript an OOP language? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JavaScript an OOP language?" Watch "JavaScript an OOP language?" New topic
Author

JavaScript an OOP language?

Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
Is JavaScript an Object Oriented programming language?

Thanks.

Be Humble... Be Nice.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Depends who you ask. You'll need to define what you mean by an object-oriented programming language.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
Bear Bibeault wrote:Depends who you ask. You'll need to define what you mean by an object-oriented programming language.


Ok does JavaScript follow the oops concepts like inheritance, polymorphism and encapsulation?

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

No.

I'd characterize JavaScript (an implementation of the ECMAscript standard) as a functional language with prototype-based objects.
Vijay Dharap
Ranch Hand

Joined: Mar 18, 2004
Posts: 32
Arjun Reddy wrote:
Ok does JavaScript follow the oops concepts like inheritance, polymorphism and encapsulation?


I would say yes.

Take a look at Supporting Technical details..

Also as 'Bear Bibeault' mentioned, the inheritance in javascript is implemented as Prototypal Inheritance rather than Implementation Inheritance.

More on Advanced Javascript search for 'Douglas Crockford — "Advanced JavaScript"' on the page.


Vijay dharap,
<a href="http://dharapvj.wordpress.com" rel="nofollow">Blog</a>
Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
Vijay Dharap wrote:
Arjun Reddy wrote:
Ok does JavaScript follow the oops concepts like inheritance, polymorphism and encapsulation?


I would say yes.

Take a look at Supporting Technical details..

Also as 'Bear Bibeault' mentioned, the inheritance in javascript is implemented as Prototypal Inheritance rather than Implementation Inheritance.

More on Advanced Javascript search for 'Douglas Crockford — "Advanced JavaScript"' on the page.


Could you tell what you meant about difference? In Prototypal inheritance, objects inherit from other objects. Same is with the normal inheritance in Java right (Classes inherit from other classes?)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Do not confuse classes with object instances. JavaScript has no concept of a class.
Vijay Dharap
Ranch Hand

Joined: Mar 18, 2004
Posts: 32

Well.. In prototypal inheritance, if you have

object A with properties aa , ab and ac

and if object B inherits object A [Notice the object A and object B are single instances of object not a contract like in case of classes in implementation inheritance]..

In above case, object B already has aa, ab and ac properties BUT... now if you change the value of any property in B.. they do not reflect back in the object A.

But if you do not change a property say ac in object B and change that in object A in stead.. the changed value of ac would be automatically be available to object B.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

There is no inheritance in JavaScript except as provided by the prototype -- and even that isn't generally considered "inheritance". It can be kinda/sorta mimicked, but that's the extent of it.

To say that JavaScript is an object-oriented language because the usual object-oriented features can be somewhat mimicked is misleading. Even the rather flawed article linked earlier calls JavaScript "object-based" rather than object-oriented.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaScript an OOP language?