ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Is JavaScript object-oriented?

user-image
تم إضافة السؤال من قبل Ahmed Abdul Fattah Al-Hamdi , Senior Software Engineer , Ejada Systems Ltd. - Egypt Branch
تاريخ النشر: 2017/01/11
Mohammad Issa
من قبل Mohammad Issa

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

Goncalo Lourenco
من قبل 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".

Muhammad Abdol
من قبل Muhammad Abdol

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

Jonathan de Flaugergues
من قبل 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();

المزيد من الأسئلة المماثلة