خصائص prototype لـ JavaScript Date

التعريف والاستخدام

prototype يسمح لك المصفوفة بإنشاء خصائص جديدة وطرق لجسم Date().

عند بناء الخاصية، سيتم منح جميع كائنات التاريخ الخاصية وقيمتها كقيمة افتراضية.

في بناء الكائن، يمكن استخدام هذا الطريقة من قبل جميع كائنات التاريخ.

ملاحظة:Date.prototype لا تشير إلى عملاً من نوع تاريخ واحد، بل تشير إلى عملاً من نوع Date نفسه.

ملاحظة:Prototype هو بناء عالمي للاعبين، ينطبق على جميع الكائنات JavaScript.

مثال

أنشئ طريقة جديدة للغة تاريخية، تقدم لمثال على الوجهة myProp من خصائص الشهر:

Date.prototype.myMet = function() {
  if (this.getMonth() == 0){this.myProp = "January"};
  if (this.getMonth() == 1){this.myProp = "February"};
  if (this.getMonth() == 2){this.myProp = "March"};
  if (this.getMonth() == 3){this.myProp = "April"};
  if (this.getMonth() == 4){this.myProp = "May"};
  if (this.getMonth() == 5){this.myProp = "June"};
  if (this.getMonth() == 6){this.myProp = "July"};
  if (this.getMonth() == 7){this.myProp = "August"};
  if (this.getMonth() == 8){this.myProp = "September"};
  if (this.getMonth() == 9){this.myProp = "October"};
  if (this.getMonth() == 10){this.myProp = "November"};
  if (this.getMonth() == 11){this.myProp = "December"};
;

أنشئ عملاً من نوع Date ثم استدعي طريقة myMet:

var d = new Date();
d.myMet();
var monthname = d.myProp;

جرب بنفسك

النحو

Date.prototype.الاسم = القيمة

تفاصيل التقنية

إصدار JavaScript: ECMAScript 1

المتصفح يدعم

خصائص Chrome IE Firefox Safari Opera
prototype الدعم الدعم الدعم الدعم الدعم

الصفحات ذات الصلة

دروس:JavaScript التاريخ

دروس:تنسيق JavaScript التاريخ

دروس:مستخرج JavaScript الكائن