Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How use "arguments" object in jquery function similar as 'this'?

I need use parameter arguments in jQuery function as my own element, not as default element. My code: I should call backbone superclass in $(window).load:

 MyController.__super__.scroll.apply(this, arguments);

I make something like this:

 var context = this;
 var contextArgs= arguments;
 $(window).load(
   function(){
   MyController.__super__.scroll.apply(context , contextArgs);  //call backbone superclass
 });

I don`t want to create new param 'context ' and 'contextArgs'. I can only prevent creation var context = this; by using Jquery.proxy:

 var contextArgs= arguments;
 $(window).load(
     $.proxy(function() {
         MyController.__super__.scroll.apply(this , contextArgs);
     },this)
 );

How prevent creation another param var contextArgs= arguments;

like image 568
Aleksandr Filichkin Avatar asked Dec 05 '25 08:12

Aleksandr Filichkin


1 Answers

You can pass in other arguments to proxy and they'll be available as arguments in the function:

$(window).load(
    $.proxy(function(contextArgs){
        MyController.__super__.scroll.apply(this , contextArgs);
    },this, arguments)
);
like image 150
freejosh Avatar answered Dec 07 '25 21:12

freejosh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!