1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 <title>内置对象</title> 6 <script> 7 ????//5.Date 8 ????//1)如何创建Date 9 ????var d1 = new Date();10 ????var d2 = new Date("2017/09/01 09:09:09");11 ????console.log(d1);12 ????console.log(d2);13 ????//2)转换为本地格式的字符串14 ????console.log(d1.toLocaleDateString());15 ????console.log(d1.toLocaleTimeString());16 ????//3)读取时间分量17 ????var y = d1.getFullYear();18 ????//月份从0开始19 ????var m = d1.getMonth()+1;20 ????var d = d1.getDate();21 ????var today = y + "年" + m + "月" + d + "日";22 ????console.log(today);23 ????24 ????//6.RegExp25 ????var str = "You can you up,no can no bb.";26 ????//1)如何创建正则对象27 ????var reg = /no/;28 ????//2)test()29 ????//检测字符串中是否包含与正则匹配的子串30 ????console.log(reg.test(str));31 ????//3)exec()32 ????//普通模式下33 ????//从字符串中检测出与正则匹配的第1个子串34 ????console.log(reg.exec(str));35 ????console.log(reg.exec(str));36 ????//全局模式下37 ????//第1次调用,则从字符串中检测出与正则匹配的第1个子串38 ????//第n次调用,则从字符串中检测出与正则匹配的第n个子串39 ????reg = /no/g;40 ????console.log(reg.exec(str));41 ????console.log(reg.exec(str));42 ????console.log(reg.exec(str));43 ????console.log(reg.exec(str));44 ????45 ????//7.Function46 ????function sum() {47 ????????var s = 0;48 ????????if(arguments.length) {49 ????????????for(var i=0;i<arguments.length;i++) {50 ????????????????s += arguments[i];51 ????????????}52 ????????}53 ????????return s;54 ????}55 ????56 ????//页面加载时立刻调用函数57 ????console.log(sum(1,2));58 ????console.log(sum(3,4,5,6));59 ????60 </script>61 </head>62 <body>63 ????64 </body>65 </html>
js内置对象
原文地址:http://www.cnblogs.com/excellent-vb/p/7729315.html