javascript - Calling a function (ex. namespace.show) by name -
i want call function namespace based on name.
perhaps background: want is, dynamically bind pages via $.mobile.loadpage(instrurl, { showloadmsg: false }); , then, based on current page, invoke function within loaded page. example: each page has showfilter function, event attached main.html - page should call matching function in current page.
i tried solutions, jquery too, nothing works me.
this function code:
function namespace() { } namespace.showfilter = function () { alert("test"); }
and want "invoke" or "call" via name. tried @ least.
$(document).ready(function() { var fn = window["namespace.showfilter"]; fn(); });
i error typeerror: fn not function
here fiddle http://jsfiddle.net/xbces/1/
you can call in following way:
$(document).ready(function() { window["namespace"]["showfilter"](); });
or
$(document).ready(function() { window["namespace"].showfilter(); });
or
$(document).ready(function() { window.namespace.showfilter(); });
Comments
Post a Comment