文章出處
文章列表
<!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>
文章列表
全站熱搜