<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<script>
var title = 'JS中要注意的东西'
// 1
//全局变量
//所有在全局定义的变量都是window下的一个属性
// 2
//作用域
//没有块作用域,变量全部在开头声明
// 3
//自动插入分号
function a(){
return {
}
};
//这就出问题了, 返回的是undefined
function b(){
return
{
}
};
//4
//保留字
var object = {}, method;
// object.case = 1; 出错了
object['break'] = 1; //没问题
//object['case'] = 1; 没问题
//object = {'case' : 1} 这个可以的
//object = { case : 1 } 高版本浏览器可以的
// ->_-> 尽量不要使用保留字;
//5
console.log( typeof null );
//判断数组或者对象要用
if( a && typeof a === 'object' ){
};
//6
console.log( typeof NaN ) // number;
console.log( NaN === NaN); //false
console.log( isNaN(NaN) ) //true
//7
//假值
var 假值 = {
'Number' : '0',
'Number' : 'NaN',
'String' : ' ',
'Object' : 'null',
'undefined' : 'undefined'
};
//hasOwnproperty;
/*
object.constructor
object.hasOwnProperty = null; 低版本的hasOwnProperty 和 constructor是可写的;
console.log( object.hasOwnProperty );
*/
/*________________割割割割割割割割割割割割割割割割割割______________________*/
var title = 'JS中的糟粕';
// 1 : == =! 和 === ==!
//邪恶的强制转换;
// 2 : with语句
//性能不好
var object = {};
object.a = 11;
object.b = null;
with(object){
b = a;
};
//eval
//性能不好
eval //全局
new Function() //全局
setTimeout('a=1',1) || setInterval('a=1',1) //全局
//缺少块语句,模糊的语句结构
if(1)a=1;
for(var i=0; i<10; i+=1)a=1;
while(a)a--;
do console.log(9)
while(a);
//包装
new Boolean;
new String;
new Number;
new Object;
new Array;
// undefined是new不出来的
</script>
</body>
</html>