javascript - Wrapping a function which uses $(this) -


i'm working on code uses jquery countdown plugin. plugin allows callback function passed executed when countdown hits zero:

{     until: new date(remaining),     onexpiry: runsomeaction } 

runsomeaction uses $(this) pick timer hit zero. i'd wrap runsomeaction way know how add paramenter it, this:

{     until: new date(remaining),     onexpiry: function() {         // logic here...         runsomeaction($(this));     } } 

but have change $(this) references in runsomeaction parameter name.

is there way wrap runsomeaction can continue using $(this) , don't have change it?

you can use call or apply javascript functions change this context given function. should work you:

onexpiry: function() {     // logic here...     runsomeaction.call($(this)); } 

now within runsomeaction function, this equal $(this) point function called.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -