Skip to content

Instantly share code, notes, and snippets.

@kg
Created June 7, 2011 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kg/1011893 to your computer and use it in GitHub Desktop.
Save kg/1011893 to your computer and use it in GitHub Desktop.
JSIL Code Sample: Closures
using System;
public static class Program {
public static void Main (string[] args) {
int x = 1;
string y = "y";
Func<string> a = () => {
return String.Format("x={0}, y={1}", x, y);
};
Console.WriteLine("a()={0}", a());
}
}
JSIL.MakeStaticClass("Program", true, [], function ($) {
$.Method({Static:true , Public:true }, "Main",
$sig.get(1, null, [$jsilcore.TypeRef("System.Array", [$.String])], []),
function Main (args) {
var $l$gc__DisplayClass = new $asm00.Program_$l$gc__DisplayClass1();
$l$gc__DisplayClass.x = 1;
$l$gc__DisplayClass.y = "y";
var a = function () {
return $asm01.System.String.Format("x={0}, y={1}", this.x, this.y);
}.bind($l$gc__DisplayClass);
$asm01.System.Console.WriteLine("a()={0}", a());
}
);
});
JSIL.MakeClass($asm01.TypeRef("System.Object"), "Program/<>c__DisplayClass1", false, [], function ($) {
$.Method({Static:false, Public:true }, ".ctor",
$sig.get(2, null, [], []),
function _ctor () {
}
);
$.Field({Static:false, Public:true }, "x", $.Int32, function ($) {
return 0;
});
$.Field({Static:false, Public:true }, "y", $.String, function ($) {
return null;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment