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
Post a Comment