• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaScript an OOP language?

 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is JavaScript an Object Oriented programming language?

Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends who you ask. You'll need to define what you mean by an object-oriented programming language.
 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.

I'd characterize JavaScript (an implementation of the ECMAscript standard) as a functional language with prototype-based objects.
 
Vijay Dharap
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do not confuse classes with object instances. JavaScript has no concept of a class.
 
Vijay Dharap
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic