0

I am new to RequireJS. Until now, when I am developing apps, I find it very useful to create a global namespace in order to be able to test and debug my app from the chrome web inspector or the like.

For example (using knockout.js), I could define my view model somewhere in the global namspace and then just inspect it with:

ko.toJSON(viewModel);

Or Using backbone.js:

var App = {};
App.Model = Backbone.Model.extend({...});

//(Lets say I want to start my app with jQuery ready function)
$(function(){
    App.model = new App.Model();
});

And then from the console to test that my model is working properly:

App.model.fetch();

Is there a way to accomplish this while using RequireJS?

Bradley Trager
  • 3,570
  • 3
  • 26
  • 33
  • 4
    Just invoke RequireJS in the console. Try `var ko = require('knockout')` See [this question](http://stackoverflow.com/questions/8458561/interacting-with-require-js-modules-from-the-firebug-chrome-console) – Gabriel Boya Nov 27 '13 at 16:24

1 Answers1

1

The way I do it is that for the modules for which it makes sense I purposely leak some values into the global space only if the code detects that it is running in a test environment.

Louis
  • 146,715
  • 28
  • 274
  • 320