SpreadElement[Yield]:
...AssignmentExpression[In, ?Yield]
Run Code Online (Sandbox Code Playgroud)
这与Spread语法相同
扩展语法允许在可能需要零个或多个参数(用于函数调用)或元素(用于数组文字)的位置扩展数组表达式或字符串等可迭代的值,或者在零或更多的位置扩展对象表达式键值对(对象文字)是预期的.
句法
对于函数调用:
Run Code Online (Sandbox Code Playgroud)myFunction(...iterableObj);对于数组文字:
Run Code Online (Sandbox Code Playgroud)[...iterableObj, 4, 5, 6]
在MDN文档中描述?
什么是SpreadElement和/或扩展语法的用例; 如果SpreadElement和传播语法不同,它们的具体方式有何不同?
import {flow, curry} from 'lodash';
const add = (a, b) => a + b;
const square = n => n * n;
const tap = curry((interceptor, n) => {
interceptor(n);
return n;
});
const trace2 = curry((message, n) => {
return tap((n) => console.log(`${message} is ${n}`), n);
});
const trace = label => {
return tap(x => console.log(`== ${ label }: ${ x }`));
};
const addSquare = flow([add, trace('after add'), square]);
console.log(addSquare(3, 1));
Run Code Online (Sandbox Code Playgroud)
我开始写跟踪2认为跟踪不起作用,因为"如何挖掘可能知道n或x什么?".
但跟踪确实有效,我不明白它如何能够"注入"来自流量的x进入点击呼叫.任何解释将不胜感激:)
这是普通 ol' js 中的管道函数:
const pipe = (f, ...fs) => x =>
f === undefined ? x : pipe(...fs)(f(x))
const foo = pipe(
x => x + 1,
x => `hey look ${x * 2} a string!`,
x => x.substr(0, x.length) + Array(5).join(x.substring(x.length - 1)),
console.log
)
foo(3) // hey look 8 a string!!!!!Run Code Online (Sandbox Code Playgroud)
我如何用类型在打字稿中写同样的东西?
即当我在管道函数时,我可以从当前最后一个函数的返回类型中获取类型信息
我喜欢柯里化,但有几个 Javascript 开发人员拒绝这种技术的原因有几个:
f(x) (y) (z)有没有一种方法可以减轻这些担忧,这样我的同事就不会讨厌我?
javascript functional-programming currying function-composition higher-order-functions
我想做一些函数组合。我已经知道这一点:
如果f3(x)应该和f1(f2(x))
那时一样f3 = _.flowRight(f1,f2);
如果f3(x,y)和f1(x, f2(y))
那时一样……?
(用例是 node.js/express 中间件函数的组合。)
我正在使用 node.js 并且显然可以访问我的签名 cookie。
它们是这种形式:
{ 'connect.sid': 's:qX4ZrttrjydtrjkgsdghsdghrewynZj4Ew2OUh.tTSILkcvgsegsegsegsr99gmW5
0XLcJefM' }
Run Code Online (Sandbox Code Playgroud)
Puppeteer 支持 cookie 并且为了传递 cookie 的参数而有这个功能:
page.setCookie(...cookies)
...cookies <...Object>
name <string> required
value <string> required
url <string>
domain <string>
path <string>
expires <number> Unix time in seconds.
httpOnly <boolean>
secure <boolean>
sameSite <string> "Strict" or "Lax".
returns: <Promise>
Run Code Online (Sandbox Code Playgroud)
如您所见,您直接提供了每个字段的参数。有没有办法将我签名的 cookie 直接传递给 puppeteer?
javascript ×3
lodash ×2
composition ×1
cookies ×1
currying ×1
ecmascript-6 ×1
node.js ×1
puppeteer ×1
session ×1
typescript ×1