4 , hasOwnProperty()和propertyIsEnumerable()方法: 1):hasOwnProperty var a = { x : 1 , y : 2}; var k =a.hasOwnProperty("x"); alert(k) //true alert( Math.hasOwnProperty("z") );//false alert( Math.hasOwnProperty("cos") );//true 注:Math,cos() : 以弧度为单位计算并返回指定角度的余弦值。 propertyIsEnumerable()跟返回的结果跟hasOwnProperty()相同;
4 ,isPrototypeOf()方法: 如果方法所属的对象是参数的原型对象。 var a = { x : 1 , y : 2}; var k1= Object.prototype.isPrototypeOf(a); // o.constructor = Object var k2= Object.prototype.isPrototypeOf(Function); // Function.constructor = Object alert(k1) //true alert(k2) //true
5,数组: 1)创建数组: 数组直接量: var es = [ ] ; 复杂点 var es = [ [ 1, {x:1 , y : 2}] , [ 2, {x:3 , y : 4}] ]; 还有一种方式:使用Array() 构造函数: V1 : 无参数: var a = new Array(); 空数组,和 var a =[ ] 相等 ;
V2 : 多个参数: var a = new Array( 1,2,3,”tt”) ; //可以看出直接量定义 简单些。
V3 : 1个数字参数: var a = new Array (3); 具有3个元素的数组,每个元素的值为 undefined ;