1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| <!DOCTYPE html>
<html> <head> <meta charset="UTF-8"> <title></title> </head> <body> </body> </html> <script type="text/javascript">
var arr = new Array(); Array.prototype.add = function(){ var sum = 0; for(var i = 0; i < this.length;i++){ sum += this[i]; } return sum; } var a1 = [289, 37, 100, 200]; console.log(a1.add()); var a2 = new Array(); a2.push(23); a2.push(100); console.log(a2.add()); Date.prototype.getWeek = function(){ var weekArray = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]; return weekArray[this.getDay()]; } Date.prototype.getChineseMonth = function(){ return ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"][this.getMonth()];
} var now = new Date(); console.log(now.getWeek()); console.log(now.getChineseMonth()); var d1 = new Date(1628374764839); console.log(d1.getFullYear()); console.log(d1.getChineseMonth()); console.log(d1.getWeek()); Date.prototype.formatString = function(){ return this.getFullYear() + "年" + this.getChineseMonth() + this.getDate() + "日 " + this.getHours() + ":" + this.getMinutes() + ":" + this.getSeconds() + " " + this.getWeek(); } console.log(now.formatString()); console.log(d1.formatString()); function Car(color){ this.color = color; } var c1 = new Car("白色"); Car.prototype.run = function(){ console.log("跑起来"); } c1.run(); </script>
|