Skip to content Skip to sidebar Skip to footer

Calling Named Function From Other Named Function In Javascript

I have run into a problem with a named function in Javascript. I have this reload function SN.Reload = function(settings) { var _timer = null; var $grid = null;

Solution 1:

No, because simply LoadData does not exist outside the scope of SN.Reload

If you do want to re-use the LoadData function, do not restrict it's scope to being inside SN.Reload and instead, perhaps (depending on what you want), attach it to the namespace as SN.LoadData

Solution 2:

Yes, if you instantiate SN.Reload. for example:

var obj = new SN.Reload(settings);

then you can use LoadData from this object, like this:

obj.LoadData();

And yes you have to make LoadData public using this:

this.LoadData = function(){/*your code*/}

Post a Comment for "Calling Named Function From Other Named Function In Javascript"