一丶判断对象是否拥有某种属性和方法
1.in运算符
var obj = {name:"zhangsan"};
alert('name' in obj); //返回 true
alert('toSring' in obj); //返回 true
2.hasOwnProperty方法 (判断是不是本身拥有的方法)
var obj = {name:"zhangsan"};
obj.hasOwnProperty("name"); //true
obj.hasOwnProperty("toString"); //false
//原型链上的属性无法通过hasOwnProperty()检测到
二丶本地对象
I.Data对象日期对象处理日期和时间
var T = window.setInterval(function(){var date = newDate(); //返回当前时间datefullyear =date.getFullYear(), //返回当前年数 2017dategetmonth =date.getMonth(), //返回当前月份 4dategetday =date.getDay(), //返回星期几dategetdate =date.getDate(), //返回多少号 日期dategethours =date.getHours(), //返回时间--时针dategetminutes =date.getMinutes(), //返回时间--分针dategetseconds =date.getSeconds(), //返回时间--秒针dategetmillisconds =date.getMilliseconds(), //返回时间--毫秒针body =document.body,arr = ["日","一","二","三","四","五","六"];
body.innerHTML= datefullyear + "年" + (dategetmonth+1) + "月"+ dategetdate + "号" + dategethours + "时"
+ dategetminutes + "分" + dategetseconds + "秒"+ "------" + "周" +arr[dategetday];
},1000);
整体效果如下:时间自动实时刷新
II.Math()对象
Math对象时javascript中的一个全局对象不需要用new创建,用来处理复杂的数学运算
Math.abs(-10); //求绝对值 10
Math.round(5.5); //四舍五入 6
Math.random(); //0-1之间的随机数
Math.random()+1; //1-2之间的随机数
Math.random()*10; //0-10之间的随机数
Math.aqrt(); //返回一个数的平方根,这个数不能是负数 可以为0
Math.hypot(3,4); //返回参数平方和的平方根
Math.ceil(); //想上去最小整数
Math.floor(); //向下取最大整数
Math.pow(a,b); //a的b次方值
Math.sign(); //判断一个数值的正负
Math.max(); //取最大值
Math.min(); //取最小值
PASS:分割线 2017-05-0913:46:30