js中使用对象变量的两种方式

function Person(){
        this.a=function(){
            window.alert("a");
        }
        this.b=function(){
            window.alert("b");
        }
        this.c="c";
        this.d="d";
    }

    var p=new Person();
    p.a();
    //p["b"];
    window.alert(p["c"]);
    window.alert(p["d"]);

运行结果:先后输出a,c,d.

猜你喜欢

转载自www.cnblogs.com/liaoxiaolao/p/9764762.html