在javascript中,如何从同一个类中的另一个方法调用类方法?

Che*_*tan 10 javascript methods class

我有这个:

var Test = new function() {  
    this.init = new function() {  
        alert("hello");  
    }
    this.run = new function() {  
        // call init here  
    }  
}
Run Code Online (Sandbox Code Playgroud)

我想init在跑步中打电话.我该怎么做呢?

Jef*_*f B 7

使用this.init(),但这不是唯一的问题.不要在内部函数上调用new.

var Test = new function() {
    this.init = function() {
        alert("hello");
    };

    this.run = function() {
        // call init here
        this.init();
    };
}

Test.init();
Test.run();

// etc etc
Run Code Online (Sandbox Code Playgroud)