Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

Is JavaScript object-oriented?

user-image
Question ajoutée par Ahmed Abdul Fattah Al-Hamdi , Senior Software Engineer , Ejada Systems Ltd. - Egypt Branch
Date de publication: 2017/01/11

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

Goncalo Lourenco
par 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
par 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