javascript - Accessing a "parent" functions' variable -
in javascript there way have mod() modify a? want do:
function whatever(){ var a=0; mod(a); var amodded=a; } function mod(obj){ obj++ a=obj; }
at end of whatever() want 'amodded' =1. there way without declaring 'a' outside of , functions?
1. make mod
such changes [properties of] a
directly:
function whatever (){ var = {value: 0}; mod(a); var amodded = a.value; } function mod(obj){ obj.value++; }
http://jsfiddle.net/derekl/2jl0we41/
2. make mod
such returns new value:
function whatever (){ var = 0, amodded = mod(a); } function mod(obj){ return ++obj; }
Comments
Post a Comment