使用:
var a = {} addMethod(a, 'test', function(x){console.log(x)}) addMethod(a, 'test', function(x, y){console.log(x+y)}) addMethod(a, 'test', function(x, y, z){console.log(x+y+z)}) // test 是function名字,当参数长度不一样时候,执行的test不一样测试:
a.test('s') > s a.test(1) > 1 a.test(1,2) > 3 a.test('1','2') > 12 a.test('1','2','3') > 123 a.test(1,2,3) > 6