google chrome - Is new line a separator in Javascript -
while debugging web spa issue, stumbled on not find concrete references online: missing comma separator between function expressions in javascript. here's details:
this works - explicit comma separator there (note - intentionally on 1 line):
var f1 = function() { console.log(1); }, f2 = function() { console.log(2);}
this doesn't seem work, trying in chrome console (again - one-liner on purpose):
var f5 = function() { console.log(5); } f6 = function() { console.log(6);} vm37860:2 uncaught syntaxerror: unexpected identifier @ object.injectedscript._evaluateon (<anonymous>:895:140) @ object.injectedscript._evaluateandwrap (<anonymous>:828:34) @ object.injectedscript.evaluate (<anonymous>:694:21)
then 1 seems work - notice missing comma:
> var f3 = function() { console.log(3); } f4 = function() { console.log(4); } < function f4() > f4() 4 < undefined > f3() 3 < undefined
i looking explanation or reference 1 why multi-line missing comma seems work.
the ramification missing comma in our source slipped build caused unexpected behavior in otherwise syntax-correct script bundle (the script snippet containing missing comma piece bundled many other components on server side , emitted single script tag browser). i.e. chrome , ff not reporting syntax errors, yet script behavior incorrect (it's complex knockout.js-based spa seemed if wrong function out of many functions same name, different scope, being called; version of knockout used 2.x).
regardless - interested if can explain console behavior pure javascript / chrome console point of view, outside of scope of knockout-based spa.
javascript assume semicolons @ line breaks. ugh. second variable global, not part of var
. http://inimino.org/~inimino/blog/javascript_semicolons
Comments
Post a Comment