2017-08-03

聚沙

函数重载

1
2
3
4
5
6
7
function addMethod(object, name, fn) {
  var old = object[name]
  object[name] = function() {
    if (fn.length === arguments.length) return fn.apply(this, arguments)
    else if (typeof old === 'function') return old.apply(this, arguments)
  }
}

Comments