开发者

Script# and attaching jQuery Events

I am using Script# 0.6 and its newly added jQuery support, so far I am very impressed.

In the C# I attach a click handler to a button like so

jQuery.Select("#myButton").Click(myHand开发者_开发知识库ler);

And it gets compiled into this JavaScript

$("#myButton").click(ss.Delegate.create(this, this.myHandler));

Is there anyway to get it compiled into

$("#myButton").click(this.myHandler);

Or even better

$("#myButton").click($.proxy(this.myHandler, this));

I realise that this is a minor issue but I would like to reduce the number of references to ss and other Script# dependencies since Script# is still in its early stages of development.


Functionally ss.Delegate.create(this, this.myHandler) is very different from this.myHandler. They provide different behavior. The former preserves the "this" object context, and the latter doesn't.

If your handler doesn't need the "this" context, i.e. in c# terms, can be a static method, then make it so, and script# will emit the following instead:

$("myButton").click(MyClass.myHandler)

Hope that helps.

There is no way to replace what gets generated, but you can (if you really want) write your own version of mscorlib.js or ss.Delegate - the compiler doesn't care, as long as your implementation matches the contract it expects from the runtime script.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜