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

JS初级感悟3
var myBoolean=new Boolean(1);                      true
var myBoolean=new Boolean(true);                   true
var myBoolean=new Boolean("true");                 true
var myBoolean=new Boolean("false");                true
var myBoolean=new Boolean("Bill Gates");           true

常数                     Math.E       
圆周率                   Math.PI      
2 的平方根               Math.SQRT2   
1/2 的平方根             Math.SQRT1_2 
2 的自然对数             Math.LN2     
10 的自然对数            Math.LN10    
以 2 为底的 e 的对数     Math.LOG2E   
以 10 为底的 e 的对数    Math.LOG10E  

Math.round(4.7);

Math.random();

RegExp 是正则表达式的缩写。

RegExp 对象有 3 个方法:test()、exec() 以及 compile()。
test() 方法检索字符串中的指定值。返回值是 true 或 false。
exec() 方法检索字符串中的指定值。返回值是被找到的值。如果没有发现匹配,则返回 null。

可以向 RegExp 对象添加第二个参数,以设定检索。例如,如果需要找到所有某个字符的所有存在,则可以使用 "g" 参数 ("global")。
var patt1=new RegExp("e","g");
找到第一个 "e",并存储其位置
如果再次运行 exec(),则从存储的位置开始检索,并找到下一个 "e",并存储其位置


compile() 方法用于改变 RegExp。
compile() 既可以改变检索模式,也可以添加或删除第二个参数。

var patt1=new RegExp("e");                                                                                                  
document.write(patt1.test("The best things in life are free"));  true                                                       
patt1.compile("d");                                                                                                    
document.write(patt1.test("The best things in life are free"));  false

浏览器对象模型(Browser Object Model)
所有浏览器都支持 window 对象。它表示浏览器窗口。