Front end development

Object Oriented Javascript Concepts

This lesson discusses about the very basic concepts of OOJS

> Encapsulation – Support for method calls on a JavaScript object as a member of a Class.
> Polymorphism – The ability for two classes to respond to the same (collection of) methods.
> Inheritance – The ability to define the behavior of one object in terms of another by sub-classing.

Simple Objects

The simplest object oriented construct in JavaScript is the built-in Object data type. In JavaScript, objects are implemented as a collection of named properties. Being an interpreted language, JavaScript allows for the creation of any number of properties in an object at any time (unlike C++, properties can be added to an object at any time; they do not have to be pre-defined in an object declaration or constructor).

So, for example, we can create a new object and add several ad-hoc properties to it with the following code:

obj = new Object;
obj.x = 1;
obj.y = 2;

Interview Questions Javascript

1. Prototypal inheritance: its limitations and benefits versus class-based inheritance

2. Whether extending built in JavaScript objects is a good idea or not and why?

Post Navigation