calling eval() in particular context

前端 未结 14 1102
说谎
说谎 2020-11-27 17:05

I have following javaScript \"class\":

A = (function() {
   a = function() { eval(...) };
   A.prototype.b = function(arg1, arg2) { /* do something... */};
}         


        
14条回答
  •  爱一瞬间的悲伤
    2020-11-27 18:11

    What worked for me was using Function constructor and calling it in specified context:

    var o = {
      x: 10
    }
    
    (new Function(`console.log(this.x)`)).call(o);

    This somehow doesn't work in browser's console but works elsewhere.

提交回复
热议问题