Making methods with binded "this" without expicitly using jQuery.proxy

17 views
Skip to first unread message

Vincas Dargis

unread,
Aug 28, 2013, 5:20:58 AM8/28/13
to jsclas...@googlegroups.com
Hello,

Is there a way to make class methods behave like ones (re?)created with jQuery.proxy(), automatically?

You may call me stubborn-c++'er, but I really hate how "this" is handled in JavaScript, and that explicit "this" binding is annoying, and bug-prone.

Currently I have code similar to:

PageComment = function()
{
   //something something
   
    //yes, I hate JS closure-style code also :)
    this.onBackButtonClicked = $.proxy(this.onBackButtonClicked, this);
    this.onSubmitButtonClicked = $.proxy(this.onSubmitButtonClicked, this);

    //... and much more...
}

Maybe there is way to declare methods that are pre-proxy'ed? What techniques do you use when handling events in class methods? If there is no implicit way to do that, may be this could be a feature request?

Thank you.

Reply all
Reply to author
Forward
0 new messages