对象
1.构造器函数
function Person(name,sex,age){
this.name = name;
this.sex = sex;
this.age = age;
this.get = function(){ return this.name+”,”+this.sex+”,”this.age}
}
var h1 = new Person(“a”,”man”,”18”);
var h2 = new Person(“b”,”man”,”20”);
h1.get();h2.get();
构造器的首字母应该大写,与其它函数区分,
3.传递对象时传递的是对该对象的引用,在该引用上的任何改动都会影响它的实际值即原对象。
4.对象的比较(===)
当且仅当两个引用指向同一个对象时为true。
5.内建对象
Object;
Array:注意有length属性,push()方法在末尾增加一个元素,pop()移除最后一个元素,join()返回一个由目标数组所有元素值连接而成的字符串,()中的参数可以指定连接元素之间的字符串,slice()切片。
Boolean:获取值的方法,valueof();
Number;
String;转换大小写函数:toUpperCase() and toLowerCase();搜索字符串indexOf(a,b):a是要查找的值,b是要找第几个a。splice():切片成为数组。concat():追加字符串。
Math:只提供方法,不支持new;random()产生0-1之间的随机数,根据自己的需求乘10或100或其他;round()四舍五入,可以配合random()使用;max(),min()找到最大最小值。
Date;
try{
var total = maybeExists();
if(total === 0){
throw {
name : “ERROR”,
MESSAGE:”OMG!ERROR!!”//抛出的异常e
}
}
else{
alert(50/total);
}
} catch (e){
alert(e.name+”:”+e.message);
} finally {
alert(“finally!!”);
}
这段程序两种情况,一种alert(e);一种得到50/roral的结果;以上任何一种情况都会弹出“finally!!”的alert。
原文:http://www.cnblogs.com/ebwill/p/5299012.html