javascript - Give selector.method as parameter, call it -
i've got function $.dosomething()
stuff , should phone call other functions in jquery-form of $('selector').function()
. not want $.dosomething()
know it's calling, should decided user.
i created little illustration on jsbin: http://jsbin.com/umonub/11/edit
is possible store phone call $('#foo').dostuff();
in function-object , give parameter function calls it?
here's sample-code (in case can't access jsbin or gets deleted there):
script.js
$(document).ready( function() { var callback = $('#foo').dostuff(); $.dosomething(callback); }); $.extend({ dosomething: function(callback) { //do stuff //call callback } }); $.fn.dostuff = function() { $(this).text("stuff done"); };
index.html
<html> <head> <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> <script src="script.js"></script> </head> <body> <p id="foo"></p> </body> </html>
sure, set $('#foo').dostuff()
within function:
var callback = function() { $('#foo').dostuff(); };
javascript jquery callback function-pointers
No comments:
Post a Comment