每日一包0019 mem

2021-09-13 01:35:53 字數 1183 閱讀 3304

mem

用於通過快取具有相同輸入的呼叫結果來加速連續函式呼叫的優化
普通用法 (支援基於promise的非同步函式呼叫)
const mem = require('mem');

let i = 0;

let a = () => i++;

let mem_a = mem(a);

mem_a();

console.log(i);//1

mem_a();

console.log(i);//1

mem_a(10);

console.log(i);//2

mem_a();

console.log(i);//2

mem_a(11);

console.log(i);//3

let b = async () => j++;

let mem_b = mem(b);

(async ()=> )();

第二引數用法

用法:mem(function, options|object)

const mem = require('mem');

const got = require('got');

const delay = require('delay');

const memgot = mem(got, );

(async () => )();

let c = (a, b) => k++;

let mem_c = mem(c);

mem_c(1, 2);

console.log(k);//1

mem_c(1, 3);

console.log(k);//2

mem_c(1, 3);

console.log(k);//2

let d = (a, b) => l++;

let mem_d = mem(d, );

mem_d(1, 2);

console.log(l);//1

mem_d(1, 3);

console.log(l);//1

mem_d(2, 3);

console.log(l);//2

每日一包0027 statuses

statuses koa2原始碼依賴 http狀態碼工具包var code status integer string 返回對應的狀態碼status 403 403 status 403 403 status forbidden 403 status forbidden 403 status 306...

每日一包0030 chalk

美化終端的字串樣式你可以像下面這樣簡單的使用它const chalk require chalk const log console.log 將樣式字串和普通字串合併使用 log chalk.blue hello world chalk.red 採用鏈式方法呼叫多個api log chalk.blu...

每日一包0024 inquirer

好用的互動命令列工具方法 1.inquirer.prompt questions promise 啟動提示介面並返回promiseconst req require inquirer req.prompt then as catch err 請輸入您的名字 小明 您的名字是 小明 2.inquire...