English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Date prototype 属性

 JavaScript Date オブジェクト

prototype属性は属性とメソッドをDate()オブジェクトに追加できます。

注意:prototypeはグローバル属性であり、ほぼすべてのオブジェクト(数字、配列、文字列、日付など)で使用できます。

文法:

Date.prototype.name = value

新しいdateメソッドを作成し、month-numeric値をmonthに変換-name値:

Date.prototype.showMonth = function() {
var arr = [39;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()];
};

それから、日付を作成して showMonth() メソッドを呼び出します:

var d = new Date();
var month = d.showMonth();// new メソッドを呼び出す

テストを見て‹/›

ブラウザの互換性

すべてのブラウザが完全にprototype属性をサポートしています:

属性
prototypeはいはいはいはいはい

 JavaScript Date オブジェクト