日期:2014-05-16  浏览次数:20311 次

JavaScript ---- Core constructor
1, Date
   var then = new Date(2010, 0, 1);
   var later = new Date(2010, 0, 1, 17, 10, 30);
   var now = new Date()
   later.getFullYear()
   later.getMonth()
   later.getDate()
   later.getDay()
   ...........

2. RegExp
   JavaScript defines a RegExp() constructor for creating objects that represent textual patterns.These patterns are described with regular expressions, and JavaScript adopts Perl's syntax for regular expressions.
   Both strings and RegExp objects have methods for performing pattern matching and search-and-replace operations using regular expressions.
   一对斜线之间的文本组成了一个正则表达式。这对斜线的第2个斜线后可以添加一个或多个字母,这可以改变模式的意思。
   例如:
        /^HTML/                  // 匹配以HTML开头的字符串
        /[1-9][0-9]*/            //匹配非0整数,后面可以跟任意多个数字
        /\bjavascript\b/i        // 匹配包含"javascript"单词,大小写敏感

   RegExp objects中一些有用的方法:
   例如:  
        var text = "testing: 1, 2, 3";          // Sample text
        var pattern = /\d+/g                    // Mathes all instances of one or more digits
        pattern.text(text)                      // => true: a math exists
        text.search(pattern)                    // => 9: position of first math
        text.match(pattern)                     // => ["1", "2", "3"]: array of all mathes
        text.replace(pattern, "#");             // => "testing: #, #, #"
        text.split(/\D+/);                      // => ["","1","2","3"]: split on non-digits.