柯里化(Currying)
安装loadsh
npm i --save lodash
function curry(f) { // curry(f) 执行柯里化转换return function(a) {return function(b) {return f(a, b);};};}// 用法function sum(a, b) {return a + b;}let curriedSum = curry(sum);// console.log("🚀 ~ file: generator.js ~ line 15 ~ curriedSum", curriedSum(1));var _ = require('lodash');function log(date, importance, message) {console.log(`[${date.getHours()}:${date.getMinutes()}] [${importance}] ${message}`);}log = _.curry(log);// log(new Date(), "DEBUG", "some debug");// log(new Date())("hello")("do something")let logNow = log(new Date());logNow("hello x2")("sss")
Blob
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title></head><body><div><p>hello</p></div><input type="file" id="input"><a id="btn">下载</a><div class="ims" id="imgs"></div></body><script>let str = `<div><p>hello</p></div>`let myblod = new Blob([str], {type: 'text/html'})myblod.text().then(res => console.log(res))btn.onclick = function (e) {this.setAttribute('download', 'test.html')this.href = URL.createObjectURL(myblod)}input.onchange = function (e) {console.log(e.target.files[0])let file = e.target.files[0];// let a = document.createElement('a')// a.setAttribute('download', file.name);// a.href = URL.createObjectURL(file)// a.click()let img = new Image();let fileRead = new FileReader();document.body.append(img)fileRead.onload = function(e){img.src = fileRead.result;}fileRead.readAsDataURL(file)// img.src = URL.createObjectURL(file)// imgs.append(img)}</script></html>
