数据类型
- 值类型: undefined,null ,boolean,number,string
- 引用类型: 对象object
属性
var person = new Object();
persion.name = "nike";
alert(person.name);// "nike"
// 值 复制
var num = 5;
var num1 = num;//num num1都是5但是二者是完全独立的,任何操作不会相互影响
// 引用 值
var obj = new Object();
var obj1 = obj;
obj1.name = "11";
alert(obj2.name);// "11"
instanceof
var person = new Object();
alert(person instanceof Object);//
延长作用域
- with 语句
- try catch的catch块
function builder(){
var qs = "sasa";
with(location){
var url = qs+href;
}
return url;
}
没有块级作用域
(没有块级作用域,如何做?)[http://imweb.io/topic/5665683bd91952db73b41f5e]
if(true){
var color = "blue";
}
alert(color);//blue
for(var i = 0,i<10,i++){
do something(i);
}
alert(i);// 10
内存管理
- 标记清除
- 引用计数
// 循环引用
var obj = new Object();
var obj2 = new Object();
obj.people = obj2;
obj2.dog = obj1;
// 解决(手动断开)
` ``
obj.people = null;
obj2.dog = null;
// 注意手工解除引用
function createPerson(name){
var local = new Object();
local.name = name;
return local;
}
var person = createPerson("xiao ming");
// 手工解除
person = null;