Skip to content


delegate in ScriptSharp being incorrectly generated as function changing the scope of 'this' in javascript #131

globalscholar opened this Issue · 2 comments

3 participants


delegates in ScriptSharp are being incorrectly generated as functions instead of ss.Delegate.create even though there is a reference to a private instance variable.
For example, if we write this in a class and _CheckData is an instance variable, then the anonymous delegate should be emitted as ss.Delegate.Create instead of function. This creates problems during javascript binding to events(click, mousedown etc), where 'this' is changed to the object on which the event happens instead of remaining the class in which the callback was defined.

//emits function in javascript
SomeCallback("SomeData", delegate
Util.Test(new string[] { _CheckData });

//emits ss.Delegate.create in javascript
SomeCallback("SomeData", delegate
_CheckData = 1;

We are using Version: 0.7.3 with some bug fixes.


Have you found solution?


A temporary workaround would be use the local variable alternative suggested above and then reference the local variable in the string array initializer.

@nikhilk nikhilk added a commit that closed this issue
@nikhilk - Fix #131: detect member references in array initializers
- Optimize generation of static ctors
@nikhilk nikhilk closed this in 27f44c7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.