回复: {}+{} incosistency

ziyunfei 446240525 at qq.com
Wed Apr 13 16:31:22 UTC 2016


If you see this then you will understand.

https://chromium.googlesource.com/chromium/src/+/4fd348fdb9c0b3842829acdfb2b82c86dacd8e0a/third_party/WebKit/Source/devtools/front_end/sdk/ConsoleModel.js#215

On 4/13/16 12:08 PM, Boris Zbarsky wrote:
> It sounds like all the actual JS engines involved get all of this right;
> the only difference is whether evaluation in the browser's console
> happens in an expression context or in a statement context.

And in particular, it seems like most browsers evaluate console stuff in 
a statement context, but Chrome is somewhat inconsistent about it.  Some 
experimentation suggests the following is happening, for various input 
strings:

1) "{}": expression context; claims to be an Object.
2) "   {}": expression context.
3) "var x = 1": statement context; defines a property named "x" on
    the global.
4) "let x = 1": statement context; creates a binding for "x".
5) "function f() {}": statement context; defines a property named "f"
    on the global.

I haven't experimented with more interesting whitespace preceding a '{' 
but it looks like the heuristic is to use expression context if the 
first non-whitespace character is '{' and to use statement context 
otherwise or something.

-Boris
_______________________________________________
es-discuss mailing list
es-discuss at mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160414/d816fc8f/attachment.html>


More information about the es-discuss mailing list