2014-02-23 49 views

回答

0

一个的jsfiddle叫它:

function test() { 
    alert('testing'); 
} 
function test2() { 
    alert('testing2'); 
    test(); 
} 
test2(); 

小提琴Fiddle

1

你可以做的是做出某种的功能池。我没有在这里快速&脏的对象常量:

var functionPool = { 

pool: {}, 
add: function (name, pFunction) { 
    functionPool.pool[name] = pFunction; 
}, 
execute: function (name) { 
    functionPool.pool[name].call(); 
}, 
executeAllBound: function(name) { 
    functionPool.pool[name].call(); 
    // TODO 
    // then iterate over all not named name 

} 

}; 

function f1() { 
    alert(42); 
} 

function f2() { 
    alert(1337); 
} 

functionPool.add("firstAlert", f1); 
functionPool.add("secondAlert", f2); 

functionPool.execute("firstAlert"); 
functionPool.execute("secondAlert"); 

functionPool.execute1llBound("secondAlert"); 

您将它们保存为KV-对,你可以很容易地执行一个或全部,或者一个开始,不是遍历所有其他。

http://jsfiddle.net/zEq9w/