javascript - How to access the inner function's variable from outer function with jQuery? -
i have saw access function inside outside, can not find exact answer on how access inner functions's variable outer function with jquery, not javascript.
i have code below
$(document).ready(function(){ var outv=1; function innerfunc(){ var innerfuncv=2; var outv=3; alert(outv); }; alert(outv); innerfunc(); alert(outv); alert(innerfunc.outv); });//$(document).ready(function() end
please help. thanks! let me know if there more info needed.
afaik, can't that, 1 option wrap context in object :
$(document).ready(function(){ var outv=1; var inner = { innerfuncv:2, outv:3, innerfunc : function (){ console.log(this.outv); } } console.log(outv); inner.innerfunc(); console.log(outv); console.log(inner.outv); });
Comments
Post a Comment