As some of you may know JScript.NET adds quite a few features to the common JavaScript language... it adds some class
syntax, some type identifier etc etc..
The main reason I use JavaScript is because I love how dynamic it is, nested function calls, variables scope etc etc... All these features seem to work fine in the .NET version, however writing this sort of code gives me Type mismatch
error:
public class Test extends Form {
var btn : Button;
function Test() {
var anotherBtn = new Button;
anotherBtn.Text = "some text";
// This is where the Type mismatch happens
anotherBtn.add_Click(function(sender:Object, e:System.EventArgs) {
Close();
});
this.Controls.Add(anotherBtn);
}
}
Application.Run(new Test);
It seems like I can't pass anonymous functions like that. If I define the add_Click
callback somewhere in the class, it works great!
How can I avoid this? I would like to code in JavaScript the way I'm always used to... can I somehow force the jsc.exe
compiler to use an older version of JScript?
Or maybe functions inside a class
are not regular JS functions? What's going on?