js 实现类似C# 委托的那种效果
function A(p) { } function C(p1, p2) { } function D(p1,p2,p3) { } function B() { var method = arguments[0]; var parms = []; for (var i = 1; i < arguments.length; i++) { parms.push(arguments[i]); } method.apply(this, parms); } function test1() { var p = "zhangSan"; B(A, p); var p1 = "liSi", p2 = "wangWu"; B(C, p1, p2); var p1 = "zhaoLiu", p2 = "liuQi", p3 = "zhouBa"; B(D, p1, p2, p3); }
另 推荐一个关于apply和call的区别 的帖子:
http://blog.csdn.net/business122/article/details/8000676