javascript - How do you use the revealing module pattern with jQuery's document.ready? -
i have following (albeit) small 'revealing module pattern' implementing code:
(function (ckspace, $, undefined) { ckspace.getloanvalues = function () { var url = "/home/updateapr"; $.get(url, { amount: $("#slider").slider("value"), length: $("#slider2").slider("value") }, function (data) { $("#loanamount").html("£"+data.loanadvance); $("#totaltorepay").html("£" + data.loangrossrepayable); $("#representative").html(data.loanapr); $("#monthlyrepayterm").html(data.loanterm); $("#monthlyfee").html("£" + data.loaninstalment); }); } } (window.ckspace = window.ckspace || {}, jquery));
i under impression using window.ckspace
able access ckspace globally root namespace of public members. however, when used in conjunction $(document).ready()
unable access ckspace
namespace unless declared within $(document).ready()
.
could explain me scoping issue here , if there anyway avoid declaring inside $(document).ready()
function?
edit: being bit forgetful seems , wasn't prefixing ckspace window when accessing within scope of $(document).ready()
ben,
if have understood concern, code snippet might you.
window.ckspace = {}; (function (ckspace) { ckspace.getloanvalues = function () { alert('i provide loans'); } } (window.ckspace || {}, jquery)); window.ckspace.getloanvalues();
fiddle: http://jsfiddle.net/gdcvt/
if not can please make more minimal internal code has no relevance scope. not sure whether objcet exist in window scope before pass function.
Comments
Post a Comment