控制台登录ember js [英] Console logging on ember js

查看:132
本文介绍了控制台登录ember js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一下为什么在Ember上的控制台上打印出来,它会给你一个字符串?但是,如果你打开它,它会给你一个功能?

I would just like to ask why is it that when you print out on the console on ember it gives you a string? but if you typeof on it, it gives you a function?

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

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

console.log(typeof sample); // function

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

Can someone explain this please? Aside with their documentation that is hard to grasp. It's really hard to debug on ember, even with ember inspector. Is there any tool or way to properly debug ember.

推荐答案

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

In terms of Ember debugging, you probably already read this: http://emberjs.com/guides/understanding-ember/debugging/

有一些很好的功能,你可以在开发过程中打开什么,获得更多的信息,发生什么事情。

There is a couple of great feature, what you can turn on during development, to get more information, what's happening under the hood.

你可以插入你的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);
});

如果你写了,你可以停止你的代码调试器在你的代码。我经常使用它来弄清楚发生了什么。

You can stop your code if you write debugger in your code. I use it quite often to figure out what's happening there.

在你的问题上,如果你扩展一个Ember类,它基本上创建一个新的函数,但是作为一个扩展类的子类。您可以查看发生的情况: https://github.com/emberjs/ember.js/blob/v1.7.0/packages/ember-runtime/lib/system/core_object.js#L536-L556

In terms of your question, if you extend an Ember class it basically create a new function, but behave as a subclass of extended class. You can check what's happening there: https://github.com/emberjs/ember.js/blob/v1.7.0/packages/ember-runtime/lib/system/core_object.js#L536-L556

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

When you run your Ember app, your app gonna be wrapped in a container, so if you need access to properties or variables, you have to use this - assume your app name is 'App':

App.__container__.lookup("controller:application").get("currentRouteName")
App.__container__.lookup("controller:application").get("currentPath")
App.__container__.lookup("controller:application").get("model")

需要一段时间才能了解如何调试您的ember应用程序,但值得学习并投入更多时间,因为稍后会很方便。

It is take a while to understand how could you debug your ember app, but worth to learn and invest more time in it, because will be quite handy later.

如果你有任何问题,请不要犹豫,评论,我们可以解决

If you have any question, don't hesitate to comment and we can solve it.

关于调试器;

这就像一个断点,你可以停止代码。 检查元素/开发者工具必须在Chrome中打开。例如: http://jsbin.com/cugetoxoyira/45

It is like a breakpoint, you can stop the code. "Inspect element"/"Developer Tool" have to be open in Chrome. Little example here: http://jsbin.com/cugetoxoyira/45

源代码: http://jsbin.com/cugetoxoyira/45/edit
在第18行中,有一个调试器; ,所以你可以在控制台或模型参数中检查什么。您必须在Chrome的开发者工具中的控制台中仅输入 controller

Source code: http://jsbin.com/cugetoxoyira/45/edit In Line 18, there is a debugger; , so you can check in your console what is in controller or in model params. You have to type in only controller in your Console in Developer Tool of Chrome.

这篇关于控制台登录ember js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆