2015年9月19日
JavaScript高级技巧
javascript是函数级别作用域,在内部都能访问,外部不能访问内部的,内部可以访问外部的。
函数会先收集变量。
function test(){
var j;
alert(j);
j=10;
}
test();
结果为:
Undefined
,注意j
的顺序。
var j=100;
~function test(){
console.log(j);
}();
~
把当前函数转为表达式输出。
this的使用
dd
window.m=100;
funciton test(){
alert(this.m);
}
window.test();
谁调用指代谁,this指向window。
this.m=1000;
var obj={
m:100,
test:function(){
alert(this.m);
return function(){
alert(this.m);
}
}
};
(obj.test())();
里面的function指向到了外面的window。
前端开发调试基础
console.log(result)
打印结果; console.error(result)
打印错误; console.info(result)
打印信息;
Last updated
Was this helpful?