JavaScript తేదీ ప్రాటోటైప్ గుణం

నిర్వచనం మరియు ఉపయోగం

prototype నిర్మాణ కాల్పన మీరు Date() ఆబ్జెక్ట్కు కొత్త గుణాలు మరియు పద్ధతులను జోడించడానికి అనుమతిస్తుంది.

నిర్మాణ గుణంలో, అన్ని తేదీ ఆబ్జెక్ట్లు గుణం మరియు దాని విలువను ప్రామాణిక విలువగా అనువందిస్తాయి.

నిర్మాణ కాల్పనలో, అన్ని తేదీ ఆబ్జెక్ట్లు ఈ మాదిరి మాధ్యమాన్ని ఉపయోగించవచ్చు.

ప్రతీక్షలు:Date.prototype అనేది ఒక విదేశీ డేట్ ఆబ్జెక్ట్ను కలిగి ఉంటుంది, కాదు Date() ఆబ్జెక్ట్ స్వయంగా.

ప్రతీక్షలు:ప్రాటిటైప్ అనేది ఒక సార్వత్రిక ఆబ్జెక్ట్ కన్స్ట్రక్టర్ ఉంది, ఇది అన్ని జావాస్క్రిప్ట్ ఆబ్జెక్ట్లకు అనువందిస్తుంది.

ప్రతిరూపం

ఒక కొత్త డేట్ మెట్హాడ్ సృష్టించండి, డేట్ ఆబ్జెక్ట్కు 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"};
;

ఒక డేట్ ఆబ్జెక్ట్ సృష్టించండి మరియు myMet పద్ధతిని కాల్ చేయండి:

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

స్వయంగా ప్రయత్నించండి

సంకేతాలు

Date.prototype.నామం = వాల్యూ

సాంకేతిక వివరాలు

జావాస్క్రిప్ట్ వర్షన్లు: ECMAScript 1

బ్రౌజర్ మద్దతు

属性 Chrome IE Firefox Safari Opera
prototype 支持 支持 支持 支持 支持

相关页面

教程:JavaScript 日期

教程:JavaScript 日期格式

教程:JavaScript 对象构造器