控制台登录ember js

ola*_*huy 12 console ember.js

我想问一下,为什么当你在ember上打印出来时它会给你一个字符串?但如果你输入它,它会给你一个功能吗?

ex. sample = Ember.Route.extend();

console.log(sample); // prints (subclass of Ember.Route)

console.log(typeof sample); // function
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下吗?除了他们难以掌握的文档.即使使用ember检查员,也很难在ember上进行调试.是否有任何工具或方法来正确调试ember.

Zol*_*tan 15

在Ember调试方面,您可能已经阅读过:http://emberjs.com/guides/understanding-ember/debugging/

有一些很棒的功能,您可以在开发过程中打开,获取更多信息,以及在幕后发生的事情.

您可以在app.js中插入:

var App = Ember.Application.extend({
  LOG_TRANSITIONS_INTERNAL:  true,
  LOG_ACTIVE_GENERATION:     true,
  LOG_VIEW_LOOKUPS:          true,
  LOG_RESOLVER:              true,
});

Ember.run.backburner.DEBUG            = true;
Ember.ENV.RAISE_ON_DEPRECATION        = true;
Ember.LOG_STACKTRACE_ON_DEPRECATION   = true;
Ember.LOG_BINDINGS                    = true;
Ember.RSVP.on('error', function(error) {
  Ember.Logger.assert(false, error);
});
Run Code Online (Sandbox Code Playgroud)

如果您debugger在代码中写入,则可以停止代码.我经常使用它来弄清楚那里发生了什么.

就你的问题而言,如果你扩展一个Ember类,它基本上创建一个新函数,但表现为扩展类的子类.你可以查看那里发生了什么:https://github.com/emberjs/ember.js/blob/v1.7.0/packages/ember-runtime/lib/system/core_object.js#L536-L556

当你运行你的Ember应用程序时,你的应用程序将被包装在一个容器中,所以如果你需要访问属性或变量,你必须使用它 - 假设你的应用程序名称是'App':

App.__container__.lookup("controller:application").get("currentRouteName")
App.__container__.lookup("controller:application").get("currentPath")
App.__container__.lookup("controller:application").get("model")
Run Code Online (Sandbox Code Playgroud)

需要一段时间才能理解你如何调试你的ember应用程序,但值得学习并投入更多时间,因为以后会非常方便.

如果您有任何疑问,请随时发表评论,我们可以解决.

关于调试器;

它就像一个断点,你可以停止代码.必须在Chrome中打开"Inspect element"/"Developer Tool".这里的小例子:http://jsbin.com/cugetoxoyira/45

源代码:http://jsbin.com/cugetoxoyira/45/edit 在第18行,有一个debugger;,所以你可以在你的控制台中检查控制器或模型参数中的内容.您只需controller在Chrome的Developer Tool中的控制台中输入内容.