javascript console.log displays different values on same object

柔情痞子 提交于 2019-12-02 09:43:51

问题


I'm working on an AngularJS app. When I console.log an object (the attrs parameter of directive linking function) the browser show unconsistent results for the parameter "editable" (see image). In Chrome, the property gets valued as both "zzz" and undefined (see 5th row vs 1st). In Safari the output is displayed differently, but on console.log(object) the "editable" property appears as "zzz", while on console.log(object.editable) the property is undefined.

Any hints ?

I think this issue is related to: console.log() showing contradictory values for the same object property


回答1:


I'll guess that your HTML is something like this

<div my-directive editable="{{someScopeProperty}}"...></div>

and that you are calling console.log() in your link function. When the link function runs, interpolated attributes are not defined yet (you need to use $observe or $watch to asynchronously get the interpolated value), so you'll get undefined if you attempt to log the value. Soon after, the value gets defined, and Chrome seems to automatically update the value (which is really a reference, I think) in the console where you logged the full object (not just the individual value).



来源:https://stackoverflow.com/questions/16571003/javascript-console-log-displays-different-values-on-same-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!