Javascript 公共数组在js类中不可访问

Javascript 公共数组在js类中不可访问,javascript,oop,Javascript,Oop,这是课程的一部分: function Table(seats){ //editables var leaveTable_position=new Array('380','0','102','20'); //runtime Table.id=0; Table.max_buy=0; Table.min_buy=0; Table.player_timeout=0; //on creation

这是课程的一部分:

function Table(seats){
    //editables
        var leaveTable_position=new Array('380','0','102','20');

    //runtime
        Table.id=0;
        Table.max_buy=0;
        Table.min_buy=0;
        Table.player_timeout=0;

    //on creation
        Table.seat=new Array();
        if (seats<5){seats=5;}
        if (seats>5){seats=9;}
        for (var i=1 ; i<=seats ; i++){
            Table.seat[i]=new Seat(i);
            Table.seat[i].create();
        }}
你知道为什么吗?我在js oop方面不是很好

不要使用此表

例如:

//runtime
    this.id=0;
    this.max_buy=0;
    this.min_buy=0;
    this.player_timeout=0;
请参阅fiddle:

请勿使用此表

例如:

//runtime
    this.id=0;
    this.max_buy=0;
    this.min_buy=0;
    this.player_timeout=0;
请参阅fiddle:

您必须使用此表而不是表格。使用Table时,您正在修改Table函数的属性

如果使用此选项,将在表类的当前实例上定义属性。如果您仍然希望为表添加前缀,请在函数中声明var Table=this。这样做的一个副作用是,您不能再从函数内部直接调用表了

function Table(seats){
        var Table = this;
    //editables
        var leaveTable_position=new Array('380','0','102','20');

    //runtime
        Table.id=0;
        Table.max_buy=0;
        Table.min_buy=0;
        Table.player_timeout=0;

    //on creation
        Table.seat=new Array();
        if (seats<5){seats=5;}
        if (seats>5){seats=9;}
        for (var i=1 ; i<=seats ; i++){
            Table.seat[i]=new Seat(i);
            Table.seat[i].create();
        }}
你必须用这个代替桌子。使用Table时,您正在修改Table函数的属性

如果使用此选项,将在表类的当前实例上定义属性。如果您仍然希望为表添加前缀,请在函数中声明var Table=this。这样做的一个副作用是,您不能再从函数内部直接调用表了

function Table(seats){
        var Table = this;
    //editables
        var leaveTable_position=new Array('380','0','102','20');

    //runtime
        Table.id=0;
        Table.max_buy=0;
        Table.min_buy=0;
        Table.player_timeout=0;

    //on creation
        Table.seat=new Array();
        if (seats<5){seats=5;}
        if (seats>5){seats=9;}
        for (var i=1 ; i<=seats ; i++){
            Table.seat[i]=new Seat(i);
            Table.seat[i].create();
        }}

您可能想阅读有关javascript中OOP编程的MSDN教程:。特别是,javascript是基于原型的编程,是一种不存在类的面向对象编程风格,在基于类的语言中,行为重用(称为继承)是通过修饰作为原型的现有对象的过程来实现的。您可能想阅读关于javascript中OOP编程的MSDN教程:。特别是,javascript是基于原型的编程,这是一种面向对象的编程风格,其中不存在类,而基于类的语言中称为继承的行为重用是通过修饰作为原型的现有对象来实现的