Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Is JavaScript object-oriented?

user-image
Question added by Ahmed Abdul Fattah Al-Hamdi , Senior Software Engineer , Ejada Systems Ltd. - Egypt Branch
Date Posted: 2017/01/11

yea javascript is object oriented but its not classless-based object oriented language  its prototype-based

Goncalo Lourenco
by Goncalo Lourenco , Full Stack Developer & IPTV Engineer , NOS

It is object oriented.

 

Example:

varcar = {brand: "Lamborghini", color: "purple", getCarInfo: function(){returnthis.color + '' + this.brand + ' car'; }}

Then:

alert(car.getCarInfo());

will popup the message: "purple Lamborguini car".

Javascript is object oriented, but its not based on classes for object orienting, but its a prototype based language

Jonathan de Flaugergues
by Jonathan de Flaugergues , software engineer , Abbeal

Obviously !

 

There are many way to create and use object in javascript.

Object literal :

var MyObject = {

  foo: 'foo',

  bar: function() { console.log(this.foo);}

}myObject = Object.create(MyObject);

myObject.bar(); // Using of my object

 

Constructor function :

function MyObject() {

  this.foo = 'foo';

}

MyObject.prototype.bar = function() {

  console.log(this.foo);

}

// Using of my object;

myObject = new MyObject();

myObject.bar();

 

EcmaScript 6 object :

class MyObject {

  constructor() {

    this.foo = 'foo';

  }

  bar() {

    console.log(this.foo);

  }

}

myObject = new MyObject();

myObject.bar();

More Questions Like This