Yes, it does, through the concept of scoping. Now does JavaScript support the last pillar of OOPS? Encapsulation:Įncapsulation is nothing but hiding the private data or the data that should not be directly accessible. This explains how JavaScript is able to achieve inheritance with a fair means. The above example shows how the object car can not only access its own properties brand and type but also the property of the parent Object like hasOwnProperty. JavaScript follows a concept of prototype inheritance which let objects access all or some properties from other objects or parent objects. Inheritance means that the child class can be derived from the parent class having all the properties of the parent class and also some additional properties of its own. ![]() This explains that JavaScript does follow the laws of Polymorphism. ![]() In the above examples, we have used the + operator where in example 1 it simply adds the two numbers while in example 2 it concats the strings a and b. To elaborate with the simplest example given below: Poly - many, Morphs - forms Polymorphism means anything with many forms. Let’s go through each one of them quickly – Polymorphism: Polymorphism, Encapsulation, and Inheritance - These are the three properties that define if any language follows OOPS laws or not. The THREE pillars of Object Oriented Programming: Let’s first discuss what are the properties of Object-Oriented language. Some people tend to suggest that it’s not at all Object-Oriented as it does not support classes just like Java does, though some suggest that it has the properties of OOPS and so it is an object-oriented language. The reason is that still there are discussions that if JavaScript is OOPS or not. The answer to the above question is Maybe. But does JavaScript complies with Object Oriented concepts? JavaScript is a single-threaded and dynamic language that can act as a multi-threaded language with the help of an event loop. With the help of a few frameworks like NodeJs JavaScript can also be run in a non-browser environment like in any OS terminal. JavaScript is a lightweight, prototype-based scripting language, which is widely used for building web pages. In this article, we will analyze whether the use of Object-Oriented Programming (OOP) concepts in JavaScript is viable.īefore getting started with the discussion, let’s have a quick glance at what is JavaScript
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |