Are the outputs of javascript parsers of different browsers the same?
Suppose th开发者_JS百科ere is a piece of JavaScript code that is supported by different browsers, for example IE and Firefox. Would the JavaScript parsers of the different browsers generate the same output (i.e., the same AST)?
Would the JavaScript parsers of the different browsers generate the same output
No, Not always, different browser have different javascript Parser, IE have JScript Engine and Mozilla have its own Javascript Engine.
For example, if you run following code
'x'.split(/(x)/).length
Firefox return 3, while IE return 0
See
- http://en.wikipedia.org/wiki/JavaScript_engine for more info
Theoretically yes, but in practise they don't. For example the following code is treated slightly different in IE vs. Firefox:
var e = 10;
try
{
e.something();
}
catch (e)
{
}
alert(e);
IE will print "[object]" whereas other browsers will print "10" because browsers other than IE assume the catch clause is a "local" variable and a different scope to the outer scope.
精彩评论