日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 默认站点!

默认站点

當前位置: 首頁 >

JS partial-application

發布時間:2023/12/4 23 豆豆
默认站点 收集整理的這篇文章主要介紹了 JS partial-application 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

為什么80%的碼農都做不了架構師?>>> ??

/* Title: Partial applicationDescription: the process of fixing a number of arguments to a function, producing another function of smaller arity */var partialAny = (function(aps) {// This function will be returned as a result of the immediately // invoked function expression and assigned to the `partialAny` var.function func(fn) {var argsOrig = aps.call(arguments, 1);return function() {var args = [],argsPartial = aps.call(arguments),i = 0;// Iterate over all the originally-spedicified arguments. If that// argument was the `partialAny._` placeholder, use the next just// passed-in argument, otherwise use the originally-specified // argument.for (; i < argsOrig.length; i++) {args[i] = argsOrig[i] === func._ ? argsPartial.shift() : argsOrig[i];}// If any just-passed-in arguments remain, add them to the end.return fn.apply(this, args.concat(argsPartial));};}// This is used as the placeholder argument.func._ = {};return func; })(Array.prototype.slice);// Slightly more legitimate example function hex(r, g, b) {return '#' + r + g + b; }var redMax = partialAny(hex, 'ff', partialAny._, partialAny._); console.log(redMax('11', '22')); // "#ff1122" // Because `_` is easier on the eyes than `partialAny._`, let's use // that instead. This is, of course, entirely optional, and the name // could just as well be `foo` or `PLACEHOLDER` instead of `_`. var __ = partialAny._;var greenMax = partialAny(hex, __, 'ff'); console.log(greenMax('33', '44'));var blueMax = partialAny(hex, __, __, 'ff'); console.log(blueMax('55', '66'));var magentaMax = partialAny(hex, 'ff', __, 'ff'); console.log(magentaMax('77'));// reference // http://msdn.microsoft.com/en-us/magazine/gg575560.aspx 參考 : https://github.com/shichuan/javascript-patterns/blob/master/function-patterns/partial-application.html

轉載于:https://my.oschina.net/i33/blog/144065

總結

以上是默认站点為你收集整理的JS partial-application的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得默认站点網站內容還不錯,歡迎將默认站点推薦給好友。