Javascript模块模式

bin*_*680 1 javascript

有什么区别如下:

function test(){
    this.init=function(){//do something}
    this.some=function(){//do something}
    function other(){}
}
Run Code Online (Sandbox Code Playgroud)

function test(){
    function init(){//do something}
    function some(){//do something}
    function other(){}

    return {'init':init, 'some':some};
}
Run Code Online (Sandbox Code Playgroud)

谢谢你的解释.

Joe*_*Joe 6

第一个例子:

var object = new test();
object.init();
Run Code Online (Sandbox Code Playgroud)

第二个例子:

var object = text(); // no new
object.init();
Run Code Online (Sandbox Code Playgroud)