javascript eval context not contains parameters in chrome -


i encountered strange error today.

when invoked below function in chrome, got:

var t = function(i){console.log(i);console.log(eval("i"));};

t("123");

//the result in chrome

123

undefined

but above code invoked in firefox, came out thought: second log statement same first.

in opinion,the eval statement use context of anonymous function runtime context, contains parameters.

i didn't find material involve eval context , parameter.

can tell me why ?


actually,i used tempo.js render html , came out similar question listed above.

the source code here:

    _replacevariables: function (renderer, _tempo, i, str) {         return str.replace(this.varregex, function (match, variable, args) {             try {                 ...                  if (variable === '.') {                     val = eval('i');                 } else if (utils.typeof(i) === 'array') {                     val = eval('i' + variable);                 } else {                     val = eval('i.' + variable);                 }                 .....             } catch (err) {                 console.log(err);             }              return '';         });     }, 

when run in chrome,the eval statement got error this:

typeerror: cannot convert null object

i can't figure out why happened, tried code @ beginning.

the chrome console implementation of console functions involves asynchronous behavior causes weird issues you've discovered.

that said, in particular case chrome logs "123" twice. find idea augment debugging output unique identifying text:

var t = function(i){console.log("param " + i);console.log("eval result " + eval("i"));}; 

the chrome console output collapses repeated lines , prefixes them little circled counter:

http://gutfullofbeer.net/so/console_chrome.png

that little "2" before "123" means logged twice.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -