user1464604
user1464604

Reputation:

debug BackboneJS + RequireJS instance variables like Collections, Models, etc

Once RequireJS has been added to the BackboneJS app, I cannot access the instance variables in the chrome console.

Here is the example :

Only BackboneJS: http://todomvc.com/architecture-examples/backbone/

Open chrome console and enter keys(window) to find the instance variable used in various BackboneJS scripts as "app" :

// instance variable app is also found under window
keys(window)
["top", "window", "location", "external", "chrome", "Intl", "v8Intl", "document", "_gaq", "_gat", "gaGlobal", "$", "jQuery", "_", "Backbone", "Store", "app", "jQuery191046978461160324514", "ENTER_KEY", "css", "cssFile", "cssRule"]

// debug the app object with Collections, Models, Views, Routers, etc
app
Object {Todo: function, todos: child, TodoView: function, AppView: function, TodoRouter: child…}
AppView: function (){ return parent.apply(this, arguments); }
Todo: function (){ return parent.apply(this, arguments); }
TodoFilter: ""
TodoRouter: child
TodoView: function (){ return parent.apply(this, arguments); }
todos: child
__proto__: Object

BackboneJS + RequireJS: http://todomvc.com/dependency-examples/backbone_require/

Open chrome console and enter keys(window) and try to find out the instance variable of BackboneJS similar to the previous example :

keys(window)
["top", "window", "location", "external", "chrome", "Intl", "v8Intl", "document", "_gaq", "requirejs", "require", "define", "_gat", "gaGlobal", "_", "$", "jQuery", "css", "cssFile", "cssRule", "Backbone", "Store", "jQuery191032673427602276206"]

// I cant debug the BackboneJS object when it is used with RequireJS

How can I access the same instance variable "app" in the BackboneJS application with RequireJS ?

Is there a way to access the Collections, Models, Views, Routers, etc of a Backbone application when RequireJS is used?

I am unable to figure this out since over a week, can anyone pls help me out?

Upvotes: 1

Views: 636

Answers (2)

Donald T
Donald T

Reputation: 10667

Use the Backbone Debugger extension for Chrome. It supports RequireJS.

Alternatively, temporarily move variables to the global scope within your script:

window.app = /* a variable you need access to */

Upvotes: 0

machineghost
machineghost

Reputation: 35813

The whole point of Require is to keep stuff out of the global scope (well, maybe not the whole point, but it's a main focus). If you want to use a Require-ed module, you have to bring it in via Require.

The syntax for this, IF you have already loaded the module in question, is:

var app = require('path/to/module');

You should be able to use that to access any Require-ed file from the debugger.

Upvotes: 2

Related Questions