javascript - Function toString() not working -


i use javascript in qml application , want insert code of function string:

function test(parameter) {     console.log("something do!"); } ... function otherfunction(otherparam) {     console.log("output: "+test.tostring()); } 

all print following:

"output: function() { [code] }" 

instead of desired string: "output: function() { console.log("something do!"); }"

p.s.: remember code worked somewhere during migrating qt 5.2 qt 5.4 , fixing cmake scripts, broke.

what problem here?

tostring applied function implementation detail. per ecma-262, should works expect, evidently, implemented, doesn't :( in case, standard allows work differently between implementations.

you depended on implementation detail, changed implementations, shouldn't surprised.

if need store code, can generate function eval-uating string, , add code property of function.

according 5th edition of ecma-262, section 15.3.4.2, function.prototype.tostring() should return implementation-defined rendition having syntax of functiondeclaration. perhaps qt's js engine here exhibits nonstandard behavior.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -