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

看不懂这段代码,谁能给解释下
JScript code

        var animal = {
            name:"",
            setNameFunc: function(n){
                this.name =  n;
            },
            getNameFunc:function(){
                return this.name;
            }
        };
        //alert(typeof animal)
       animal.setNameFunc("Dog");
       
       document.write("<br> animal.getNameFunc() :"+animal.getNameFunc());



animal 是数组吗? 怎么里面可以定义函数?

------解决方案--------------------
这里animal是对象
------解决方案--------------------
是对象,里面定义的是属性或方法
------解决方案--------------------
{}是对象,里面可以有名值对,如{a:1,b:"xx",c:function(){}}

各个名值对用,分开
名的部分用变量名的形式,或者双引号引起来的字符串
值的部分可以是任意类型的值,包括数字,字符串,函数,或者其它{}起来的对象