1、单体对象
Global对象(全局),这个对象不存在,无形的对象,其内部定义了一些方法和属性
encodeURI、encodeURIComponent、decodeURI、decodeURIComponent、eval、parseInt、parseFloat、isNaN、 escape、unescape
下面对这几个方法逐一讲解:
a、encodeURI和encodeURIComponent
var uri = 'http://www.bjsxt.com cn';
document.write(encodeURI(uri)); // http://www.bjsxt.com%20cn
document.write(encodeURIComponent(uri)); //http%3A%2F%2Fwww.bjsxt.com%20cn
document.write("<br/>"); //document.write(decodeURI(uri)); //http://www.bjsxt.com cn
document.write(decodeURIComponent(uri)); //http://www.bjsxt.com cn
b、eval(String)无形的js解析器
var str = "var a = 10; var b = 20";
eval(str); alert(a); //10
//数组字符串转成对象
var str = "{name:'z3',age:15}";
var obj = eval('('+str+')');
alert(obj.name); //z3
c、escape和unescape,针对汉字进行编码和解码
var str = "尚学堂";
document.write(escape(str)); //%u5C1A%u5B66%u5802
document.write(unescape(str));//尚学堂
Math对象 和Java类似
2、Date对象
var date = new Date(); //产生一个日期对象
document.write(date); //
Tue May 24 2016 19:31:57 GMT+0800 (中国标准时间)
var year = date.getFullYear();
document.write(year); // 2016
var month = date.getMonth() + 1; //外国的时间月份得加 1
document.write(month); // 5
var day = date.getDate();
document.write(day); // 24
var hours = date.getHours();
document.write(hours); //19
var minutes = date.getMinutes();
d
ocument.write(minutes); //38
var seconds = date.getSeconds();
document.write(seconds); // 43
var week = date.getDay();
document.write(week); //获得星期几
//
今天是:2016年5月24日 19:42:9 星期2
document.write('今天是:'+ year +'年'+month+'月'+day+'日'+' '+hours+':'+minutes+':'+seconds+' '+'星期'+week);
3、基本包装类型:Boolean、String、Number,和Java的用法类似,在此就不一一介绍。
4、function类型、正则表达式类型(以后介绍)