日期:2014-05-16  浏览次数:20424 次

js学习笔记4
11. function详解 P121  P717   function  构造函数

  12. js中的throw
  function factorial(x){
       if(x<0) throw new Error("x must not be negative");
  }
  function transact(){
     try{
factorial(-1);
     }catch(e){
alert(e);
    }finally{
    alert(x);
    }
  }
  P122 6.16
  13.with (扩展作用域链) 如果多次访问这个表单,可以使用with语句将这个表单添加到作用域链中:
   with(frames[1].document.forms[0]){
   name.value="";
   address.value="";
   email.value="";
   }
   然后有时使用with语句比较方便,但是它的运行速度不比不使用with语句的等价代码要慢的多。 而且在with语句中的函
   数定义和变量初始化可能会产生令人惊讶的和直觉的相抵触的行为。因此建议避免使用with的语句。
  
   14.javaScript语句的语法 P127 6-1
  
  
   15.创建对象属性 P130 7.2
var book={};
book.title="javaScript:The Definitive Fuide";
book.chapter1=new Object();//给book.chapter1实例一个Object的对象
book.chapter1.title="Introduction to JavaScript";
book.chapter1.pages="11";
book.chapter2={title:"Lexical Structure",pages:6};

for(var i in book.chapter2){
      document.write(i);  //output 该对象book.chapter2的键也就是 title和pages
      document.write(book.chapter2[i]);//output 该对象book.chapter2的值也就是 "Lexical Structure"和6。注:book.chapter2[i] 根据i得到的键获取该键的值
}
if("title" in book.chapter2)    //Result true