有谁知道为什么test1无法编译?
class Y { public myMethod: any; };
class QQ { public test(name, fun: () => any) { } }
var qq = new QQ();
qq.test("Run test1", () => {
        var outer = 10;
        Y.prototype.myMethod = () => {
          // Error: The name 'outer' does not exist in the current scope
            outer = 11;
        }
});
但以下工作:
   qq.test("Run test2", () => {
            var outer = 10;
            var fun = ()=> { outer = 11; };
            Y.prototype.myMethod = fun;
    });
所需代码的JavaScript版本如下所示:
qq.test("Run test1", function () {
    var outer = 10;
    Y.prototype.myMethod = function () {
        outer = 11;
    };
});
外部函数在其闭包中声明了一个变量“outer”,内部函数自然应该可以看到该变量。