2015-09-16 27 views
0

我想用Javascript Module PatternKnockout JS and Pager JS,我知道如何使用Javascript Module PatternKnockout JS and Pager JS分開,但我不知道如何整合them.Here是我的Javascript Module Pattern如何使用Knockout JS和Pager JS來使用Javascript模塊模式?

var Module = (function(){ 
    var my = {}; 

    my.testMethod = function(){ 
     alert("test method is called"); 
    }; 
    return my; 
}()); 

(function(anyobj){ 

    anyobj.anotherMethod = function(){ 
     alert("another Method is called"); 
    }; 

    anyobj.testMethod(); 

}(Module)); 

代碼下面這段代碼工作找到,但我不知道如何整合,以便下面的代碼給定上面的代碼,使knockout js and pager js做工精細用Javascript Module Pattern

var moduleViewModel = new Module(); 
pager.extendWithPage(moduleViewModel); 
ko.applyBindings(moduleViewModel); 
pager.start(); 

回答

1

更新下面這一個代碼,這應該工作

var Module = (function(){ 
    var my = {}; 

    my.testMethod = function(){ 
     alert("test method is called"); 
    }; 
    return my; 
}()); 

(function(anyobj){ 

    anyobj.anotherMethod = function(){ 
     alert("another Method is called"); 
    }; 

    anyobj.testMethod(); 

}(Module)); 

//--- Module is an Object so we can pass it to a function as an argument ---// 
pager.extendWithPage(Module); 
ko.applyBindings(Module); 
pager.start();