English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
prototypeProperties can add properties and methods to your Date() object.
Note:Prototype is a global property that is available for almost all objects (numbers, arrays, strings, dates, etc.).
Date.prototype.name = value
Create a new date method, which will set the month-numeric value to month conversion-name value:
Date.prototype.showMonth = function() { var arr = ['Jan#39;,'Feb#39;,'Mar#39;,'Apr#39;,'May#39;,'Jun#39;,'Jul#39;,'Aug#39;,'Sep#39;,'Oct#39;,'Nov#39;,'Dec#39;]; return arr[this.getMonth()]; };
Then create a date and call the showMonth() method:
var d = new Date(); var month = d.showMonth();// calling new method
All browsers fully support the prototype property:
Properties | |||||
prototype | Yes | Yes | Yes | Yes | Yes |