انتقل إلى محتوى الدرس
فقرة فرعية #4 من درس: Object Prototypes

Adding Methods

في هذا الدرس سوف نتعرف علي خاصية ال Prototypes في Javascript Objects 
1 صفوف تعليمية
جافا سكريبت
2,793 مشاهدة

شرح صفوف ومحتوى الفقرة

الصف 1 شرح توضيحي

نستطيع اضافة دالة Method الي object معين عن طريق استخدام ال prototype كما في المثال التالي 

Example

HTML
function Person(first, last, age, eyecolor) {
  this.firstName = first;
  this.lastName = last;
  this.age = age;
  this.eyeColor = eyecolor;
}

Person.prototype.name = function() {
  return this.firstName + " " + this.lastName;
};

Example

HTML
function Person(first, last, age, eyecolor) {
  this.firstName = first;
  this.lastName = last;
  this.age = age;
  this.eyeColor = eyecolor;
}

Person.prototype.nationality = "Arabic ";