Using quadratic notation, you are actually asking to execute a function in a window called arc.view.say_hello
, not a function in a view
object (this is a property of the arc
object). To be more explicit:
window["arc.view.say_hello"] = function () { alert("hi") }; window["arc.view.say_hello"](); // "hi"
If you want to call the function as you described, you need to "enable" the chain of objects. You can create a utility function for this purpose. Sort of:
var arc={}; arc.view={ say_hello: function(){ alert("I want to say hello"); } } function say_goodbye(){ alert("goodbye to you"); } function call(id) { var objects = id.split("."); var obj = this; for (var i = 0, len = objects.length; i < len && obj; i++) obj = obj[objects[i]]; if (typeof obj === "function") obj(); } call("say_goodbye"); call("arc.view.say_hello");
You can also extend the utility function to use arguments
(or you can simply return a link to the function).
source share