将属性和方法添加到Date原型中
<button onclick="myFunction()">点我</button> <script> Date.prototype.myMet=function(){ if (this.getMonth()==0){this.myProp="一月"}; if (this.getMonth()==1){this.myProp="二月"}; if (this.getMonth()==2){this.myProp="三月"}; if (this.getMonth()==3){this.myProp="四月"}; if (this.getMonth()==4){this.myProp="五月"}; if (this.getMonth()==5){this.myProp="六月"}; if (this.getMonth()==6){this.myProp="七月"}; if (this.getMonth()==7){this.myProp="八月"}; if (this.getMonth()==8){this.myProp="九月"}; if (this.getMonth()==9){this.myProp="十月"}; if (this.getMonth()==10){this.myProp="十一月"}; if (this.getMonth()==11){this.myProp="十二月"}; } function myFunction(){ var d = new Date(); d.myMet(); var x=document.getElementById("demo"); x.innerHTML=d.myProp; } </script>