0

I'm trying to call a function from a variable containing it's name.

More precisely, my idea is to have a timed "master" function, which will call a set of functions every n seconds.

The set of functions to call would be defined in an array, populated by names based on the called page.

Found this in jquery: Calling a Jquery function from variable value but no luck.

Any suggestions on how to achieve this?

Thnx.

EDTI

Here's a stub of code i'm working on:

var exec = "updateClock";
var updateClock = function () {
     //something nice here :)
};

var timer = setInterval(function () {
    $scope.$apply([exec]);
}, 15000);
5
  • 1
    You should share the code of what you have tried. You can store function references in variables or with angular in $scope variables. Maybe if you show what you have tried it would be easier to help. Functions calling other functions is called functional programming and is very common in javascript :). Commented Sep 3, 2015 at 12:41
  • 1
    why strings? You can store references to functions themselves. Commented Sep 3, 2015 at 12:43
  • Pages are generated dynamically, each page has it's own set. So the idea is to write the function array server side. Commented Sep 3, 2015 at 14:48
  • Make the function a property on an object and then someObject[exec].call(). Commented Sep 3, 2015 at 14:50
  • Ok, I like the object approach. Will give it a try. Commented Sep 3, 2015 at 14:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.