2020-01-10
描述
创建一个函数,使其可以调用指定对象中的属性方法,并且还可以支持将后续提供的任意参数作为柯里化函数中的单一参数。
提示
- 返回一个使用 Function.prototype.apply()绑定context[fn]为context的function
- 使用扩展运算符  ...展开后续提供的任意参数和单一参数作为function中的参数
代码
const bindKey = (context, fn, ...boundArgs) => (...args) =>
  context[fn].apply(context, [...boundArgs, ...args]);
示例
按顺序打印出延迟的时间:
const vditor = {
  user: 'vanessa',
  greet: function(greeting, punctuation) {
    return greeting + ' ' + this.user + punctuation;
  }
};
const vditorBound = bindKey(vditor, 'greet');
console.log(vditorBound('hi', '!')); // 'hi vanessa!'
 
         ME!
                
                ME!
             链滴
                
                链滴