连续通话CONSOLE.LOG产生不一致的结果 [英] Consecutive calls to console.log produce inconsistent results

查看:164
本文介绍了连续通话CONSOLE.LOG产生不一致的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我这个彻底傻眼了。 (我可能会忽视的东西明显,但...)

Ok, I'm completely dumbfounded by this. (and I might be overlooking something obvious but...)

我已经连续2调用CONSOLE.LOG。没有别的它们之间

I have 2 consecutive calls to console.log. There isn't anything else between them

console.log($state);
console.log($state.current);

和这里的产生的结果的图像

and here's an image of the produced results

为什么2产生不同的当前的对象?怎么能这样呢?

Why do the 2 produce different "current" objects? How can this happen?

这些调用的Ajax调用内作出,而解决的路径依赖。如果您需要更多code或上下文让我知道。

Those calls are made inside an ajax call while resolving a route dependencies. If you need more code or context let me know.

确认Chrome和Firefox同样的问题。

Confirmed the same issue in Chrome and Firefox

Ajax调用和包装功能(无任何修改)

normaCtrl.publicNorma = ['$http', '$state', '$stateParams', 'baseUrl', function ($http, $state, $stateParams, baseUrl)
{
    var id = $stateParams.id;
    return $http.get(baseUrl + "api/public/norma/" + id).then(
        function (response) {
            console.log($state);
            console.log($state.current);
            console.log($state.current.title);
            return response.data;
        }
    );
}];


可能相关的问题


  • <一个href=\"http://stackoverflow.com/questions/16571003/javascript-console-log-displays-different-values-on-same-object?rq=1\">javascript的console.log显示同一对象的不同值

    <一个href=\"http://stackoverflow.com/questions/20910295/angularjs-weird-console-log-behavior-with-async-chrome-storage-local-get?rq=1\">AngularJS:与异步chrome.storage.local.get怪异的console.log行为()

    推荐答案

    嗯,这里是为那些在这一点,绊倒了答案。

    Well, here's the answer for those that stumble upon this.

    CONSOLE.LOG有深可变对象在执行的最后状态,不是当的console.log被称为在状态

    Console.log shows deep mutable objects at the last state of execution, not at the state when console.log was called.

    基本上,可变深对象时,CONSOLE.LOG存储引用说的对象,而不是存储对象的克隆。

    Basically, when working with mutable deep objects, Console.log stores the reference to said object instead of storing an object clone.

    既然有存储和可视化,当你点击进行进一步的检查,你看到的箭头之间的时间差距实际上对象的当前状态并不会在状态时的console.log被称为对象的

    Since there is a time gap between storing and visualization, when you click the arrow for further inspection what you're seeing is actually the current state of the object and not the the state of the object when console.log was called.

    一个方法始终确保您使用的是对象快照是调用 Json.stringify 或使用 console.dir 时可用。

    One way to always make sure you're using an "object snapshot" is to call Json.stringify or use console.dir when available.

    这篇关于连续通话CONSOLE.LOG产生不一致的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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