Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day264:请实现 uncurring 完成函数柯里化 #1084

Open
Genzhen opened this issue Mar 23, 2021 · 1 comment
Open

Day264:请实现 uncurring 完成函数柯里化 #1084

Genzhen opened this issue Mar 23, 2021 · 1 comment
Labels
JavaScript teach_tag

Comments

@Genzhen
Copy link
Collaborator

Genzhen commented Mar 23, 2021

var yideng = Array.prototype.push.uncurring();
(function () {
  yideng(arguments, 4);
  console.log(arguments); // [1,2,3,4]
})(1, 2, 3);

每日一题会在下午四点在交流群集中讨论,五点小程序中更新答案
欢迎大家在下方发表自己的优质见解

二维码加载失败可点击 小程序二维码

扫描下方二维码,收藏关注,及时获取答案以及详细解析,同时可解锁800+道前端面试题。


答案

Function.prototype.uncurring = function () {
  var _self = this;
  return function () {
    var obj = Array.prototype.shift.call(arguments);
    return _self.apply(obj, arguments);
  };
};
@Genzhen Genzhen added the JavaScript teach_tag label Mar 23, 2021
@luuman
Copy link

luuman commented Nov 5, 2021

Function.prototype.uncurring = function() {
  let self = this
  // this 指向push
  return function() {
    // 删除数组第一位,并返回
    const obj = Array.prototype.shift.call(arguments);
    // 数组合并
    self.apply(obj, arguments)
  }
}

var yideng = Array.prototype.push.uncurring();
(function () {
  yideng(arguments, 4);
  console.log(arguments); // [1,2,3,4]
})(1, 2, 3);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JavaScript teach_tag
Projects
None yet
Development

No branches or pull requests

2 participants