javascript - How to get the scope from where a function was called? -
this question has answer here:
i'm trying create javascript expression parser, able parse expression , declared variables in body, without executing function:
function test(expressionfn) { var expression = getexpression(expressionfn); // value expression.expressionright in scope // not work -> var valuerigthinscope = expressionfn.prototype.constructor[[[scopes]]][expression.expressionright]; console.log(expressionfn.prototype); // see ".constructor[[[scopes]]]" in debug tools [f12] } function getexpression(expressionfn) { var strafterreturn = expressionfn.tostring().split("return")[1].trim(); let strexpression = strafterreturn.split(";")[0].split(" "); return { expressionleft: strexpression[0], operator: strexpression[1], expressionright: strexpression[2] }; } function start(){ var myvalue = "this value!"; test(function(x) { return x.prop1 == myvalue; }); } start();
<h1>see console</h1>
but can not access scope of function value of variable myvalue
, example.
in google chrome console managed through function scope variable myvalue
declared, can not access same scope in javascript.
follows image of google chrome console:
how can access [[scopes]]
in image?
Comments
Post a Comment