Javascript Object oriented programming

  • JavaScript is a prototype-based language which contains no class statement. Instead JavaScript uses functions as classes. Defining a class is as easy as defining a function.
  • An object constructor/object constructor function is a function that’s used to define a new object. In this function, we declare the initial properties/methods of the new object, and usually assign them a pre-defined value.
  • To create an instance of an object, we use the keyword “new”, followed by an object constructor. We can either use JavaScript’s built-in constructors to create a native object, or we can build our own constructors to create a user-defined object.
  • Every object method has a variable – this – which refers to the current instance of that object from which the method is called.


     function Computer(name) {
          this.getName=function() {

     var computer1 = new Computer("Desktop-1");
     alert(computer1.getName());//alerts Desktop-1
     var computer2 = new Computer("Desktop-2");
     alert(computer2.getName());//alerts Desktop-2


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: