将RequireJS添加到BackboneJS应用后,我无法在chrome控制台中访问实例变量。

这是示例:

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

打开chrome控制台并输入keys(window)来查找各种BackboneJS脚本中使用的实例变量“ 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/

打开chrome控制台并输入keys(window)并尝试找出BackboneJS的实例变量,类似于前面的示例:

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


如何使用RequireJS在BackboneJS应用程序中访问相同的实例变量“ app”?

使用RequireJS时,是否可以访问骨干应用程序的集合,模型,视图,路由器等?

自一个多星期以来,我无法弄清楚这一点,有人可以帮助我吗?

最佳答案

Require的全部要点是使内容不在全局范围内(嗯,也许不是重点,但这是主要重点)。如果要使用Require-ed模块,则必须通过Require引入。

如果您已经加载了相关模块,则其语法为:

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


您应该能够使用它从调试器访问任何必需文件。

关于javascript - 调试BackboneJS + RequireJS实例变量,例如Collections,Models等,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16919818/

10-10 05:47