首页 > 技术文章 > Functions类,一个Javascript的函数加法类,将两个函数加起来,顺序执行

sunsoftresearch 2014-07-17 08:21 原文

以下是类的代码:

 1 var Functions = {
 2     oFunctions: null,
 3     add: function (oFunc, oNewFunc) {
 4         var oNew = function () {
 5             oFunc();
 6             oNewFunc();
 7         };
 8         return oNew;
 9     }
10 };

以下是测试代码:

 1 function one() {
 2     alert(1);
 3 }
 4 
 5 function two() {
 6     alert(2);
 7 }
 8 
 9 one = Functions.add(one, two);
10 one();

推荐阅读