标签:
基本类型:string number boolean null Undefined
引用类型:内存中的对象
动态的属性:
1 var Person = new Object(); 2 Person.name = "js"; 3 Person.age = 19; 4 alert(Person.name); 5 //如果对象不被销毁或者这个属性不被删除,这个属性将一直存在
1 var Num1 = 1; 2 var Num2 = Num1; 3 Num1 = 2; 4 alert("Num1" + Num1 + "\nNum2" + Num2); 5 //基本类型复制
1 var obj1 = new Object(); 2 var obj2 = obj1; 3 obj1.name = "obj1"; 4 obj2.name = "obj2"; 5 alert("obj2.name" + obj2.name + "\nobj1.name" + obj1.name); 6 //引用类型复制
1 var obj = new Object(); 2 obj.name = "obj1"; 3 function setName(obj) { 4 obj.name = "after setName"; 5 } 6 setName(obj); 7 alert(obj.name);//after setName 8 9 var obj2 = new Object(); 10 obj2.name = "obj2"; 11 function setName2(obj) { 12 obj = new Object(); 13 obj.name = "this is new obj‘s Name"; 14 } 15 alert(obj2.name);//obj2
检测类型
type of 检测基本类型
var ty1 = 1;//Number var ty2 = "ty2";//String var ty3 = false;//Boolean var ty4 = new Object();//Object var ty5 = null;//Object var ty6;//undefined alert(typeof ty1); alert(typeof ty2); alert(typeof ty3); alert(typeof ty4); alert(typeof ty5); alert(typeof ty6);
instanceof 检测引用类型
1 var arry = [1, 2, 3]; 2 alert(arry instanceof Array);//true 3 4 var person = new Object(); 5 alert(Object instanceof Object);// true
标签:
原文地址:http://www.cnblogs.com/imhello/p/4338590.html