does anyone know why test1 fails to compile?
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;
}
});
But the following works:
qq.test("Run test2", () => {
var outer = 10;
var fun = ()=> { outer = 11; };
Y.prototype.myMethod = fun;
});
The JavaScript version of the required code would look look like this:
qq.test("Run test1", function () {
var outer = 10;
Y.prototype.myMethod = function () {
outer = 11;
};
});
The outer function declares a variable "outer" within its closure, which should naturally be visible to the inner function.