function Foo () { } Foo.prototype = { m1: function () { console.log('m1'); }, m2: function () { console.log('m2'); }, $eval: function (exp) { var val; with (this) { val = eval(exp); } return val; } }; var scope = new Foo(); scope.value = 'world!'; scope.$eval('m1()'); console.log(scope.$eval('"hello " + value')); console.log(scope.$eval('"hello!"')); 不用with和eval,如何实现一个Foo对象,可以对'"hello " + value','m1()'等等进行计算
添加回答
举报
0/150
提交
取消