1.Gobal对象,除Math对象之外的其他全局对象和方法,是window对象的部分实现
需要特别注意的是Golbal对象只在逻辑上是存在的,无具体的使用,包括使用其方法以及打印等,见下例
var box = 'Lee'; //console.log(Global.box);//undefined global为特殊对象,并不具体存在 console.log(window.box);
var global = function(){ <span style="white-space:pre"> </span>return this; }(); console.log(global);//打印window,类似原型
var box = '//Lee李'; console.log(encodeURI(box));//只编码了中文 console.log(encodeURIComponent(box));//特殊字符和中文都编码了 console.log(decodeURI(encodeURI(box)));//解码 console.log(decodeURIComponent(encodeURIComponent(box)));3.eval方法的使用
console.log(eval('var box = 100'));//解析了字符串代码 console.log(box);//100 console.log(eval('alert(100)'));//弹窗显示100 console.log(eval('function box(){return 123;}')); console.log(box());//123 console.log(window.Array);4.Math对象的属性及其方法
4.1Math对象的属性,主要是数学计算中会用到的一些特殊值
console.log(Math.E);//自然对数 console.log(Math.PI);//圆周率4.2min和max方法,用于确定一组数值中的最大值和最小值
console.log(Math.min(2,5,8,4,9,2,0,1));//0 console.log(Math.max(2,5,8,4,9,2,0,1));//94.3舍入方法,包括ceil(向上舍入)、floor(向下舍入)和round(四舍五入)
//向上舍入 console.log(Math.ceil(25.9));//26 console.log(Math.ceil(25.5));//26 console.log(Math.ceil(25.1));//26 //向下舍入 console.log(Math.floor(25.9));//25 console.log(Math.floor(25.5));//25 console.log(Math.floor(25.1));//25 //四舍五入 console.log(Math.round(25.9));//26 console.log(Math.round(25.5));//26 console.log(Math.round(25.1));//254.4random方法,返回介于0和1之间的1个随机数,不包括0和1.具体应用,产生介于start(整数)和end(整数)之间(start<end)的随机数为Math.floor(Math.random*(end-start+1)+start)
//随机数 console.log(Math.random()); for(var i=0;i<10;i++){ document.write(Math.floor(Math.random()));//0 document.write('<br/>'); } for(var i=0;i<10;i++){ document.write(Math.floor(Math.random()*10+1));//1-10之间 document.write('<br/>'); } for(var i=0;i<10;i++){ document.write(Math.floor(Math.random()*10+5));//5-14之间 document.write('<br/>'); } for(var i=0;i<10;i++){ document.write(Math.floor(Math.random()*6+5));//5-10之间 document.write('<br/>'); } function select(start,end){ var total = end-start+1; return Math.floor(Math.random()*total+start); } for(var i=0;i<10;i++){ document.write(select(1,3));//1-3之间 document.write('<br/>'); }4.5其它方法,比如abs(求绝对值)和sqrt(求平方根)
console.log(Math.abs(-5));//5 console.log(Math.sqrt(9));//3暂时整理这么多吧,之后具体使用时再作补充。