例定義一個方法,爲Date對象添加一個新的成員方法,轉換爲形如 y-m-d<br>h:m:sthis
Date.prototype.stringify = function(){ var s= this.getFullYear()+'-'; s+= (this.getMonth()+1)+'-'; s+= this.getDate()+' '; s+= this.getHours()+':'; s+= this.getMinutes()+':'; s+= this.getSeconds(); return s; }
Date對象能夠直接調用stringify()方法spa