var book = new Object();
book.title = "javascript : the definitive guide";
book.chapter1 = new Object();
book.chapter1.title = "Introdution to javascript";
book.chapter1.pages = 19;
book.chapter2 = {title:"Loxical Strucutre", page:6};这段代码我想给它归拢到一起,是我下面写的那样吗?var book = {
title:"javascript : the definitive guide", 
chapter1:{title:"Introdution to javascript", pages:19},
chapter2:{title:"Loxical Strucutre", page:6}
}; 如果我写的对的话,再请问了,chapter2:{title:"Loxical Strucutre", page:6}中的title是属性名还是属性值?他相对于"Loxical Strucutre"来说是属性名,但是相对于chapter2又是属性值。

解决方案 »

  1.   

    楼主的写法没有问题
    var book = {
    title:"javascript : the definitive guide",  
    chapter1:{title:"Introdution to javascript", pages:19},
    chapter2:{title:"Loxical Strucutre", page:6}
    };  这种叫json对象 其特点就是键值对的形式 其可以嵌套 就是你的chapter1和chapter2的这种
      

  2.   

    楼主的写法没有问题
    var book = {
    title:"javascript : the definitive guide",   
    chapter1:{title:"Introdution to javascript", pages:19},
    chapter2:{title:"Loxical Strucutre", page:6}
    };   这种叫json对象 其特点就是键值对的形式 其可以嵌套 就是你的chapter1和chapter2的这种
      

  3.   

    写法没错,title是chapter2的一个属性,所以是属性名,"Loxical Strucutre"是chapter2的属性值。
      

  4.   


    //里面的title都是属性名,可以这样理解,冒号前的都是属性名,后面的都是属性值
    var book = {
        "title": "javascript : the definitive guide",
        "chapter1": {
            "title": "Introdution to javascript",
            "pages": 19
        },
        "chapter2": {
            "title": "Loxical Strucutre",
            "page": 6
        }
    }