2016-04-04 55 views
0

我一直在這樣定義我的控制器一段時間(沒有任何庫),但依賴關係使我瘋了,現在我試圖整合requireJs。使用新的定義模塊requirejs

controller = new function() { 

    this.test = "Hello World"; 

    this.__construct = function() { 
     alert(this.test); 
    }; 

    this.__construct(); 

}; 

如何將其轉換爲requireJs模塊?我試過以下

define(function() { 

    return controller = new function() { 

     this.test = "Hello World"; 

     this.__construct = function() { 
      alert(this.test); 
     }; 

     this.__construct(); 
    }; 

}); 

我可以簡單地做嗎?

define(controller); 

在我的主

//main.js 
requirejs(['controller']); 

然而,警報彈出不會出現。

回答

1

controller定義應該沒問題 - 但是,你濫用在您需要main.js

//main.js 
requirejs(['controller'], function(controller){ 
    // use controller here 
});