简而言之,那么
в файле First.js
function curry(f) {
return function (a) {
return function (b) {
return f(a, b);
}
}
}
let foo = curry(onAuthStateChanged);
let foo1 = foo(auth);
export { foo1 }
------------------------------------
в файле Second.js
import { foo1 }
foo1(user => {
console.log(user); ---> значение user
})
有一个函数是通过 CDN 从 firebase-auth 导入的。它显示当前是否被授权。用户与否。
在一个文件中,我们将其称为 First.js,我将其导入,auth par 是身份验证服务的初始化。
onAuthStateChanged(auth, (user)=>{
if (user) {
...что-то делаю...
} else {
...что-то делаю...
}
})
问题是,我可以以某种方式在已插入 auth 参数的情况下导出此函数吗?
我做了什么:
- 第一的
const foo = onAuthStateChanged;
export { foo }
在 Second.js 文件中
import { foo } from "./First.js"
import { auth } from "./init.js"
foo(auth, (user)=>{
})
它有效,但我不想从 init.js 中提取身份验证
- 第二
const foo = onAuthStateChanged(auth);
export { foo }
在 Second.js 文件中
import { foo } from "./First.js"
foo((user)=>{
})
它不起作用,会引发错误
向知识渊博的社区寻求帮助。
我将提供一个带有函数柯里化的变体
onAuthStateChanged..如果你用这样的“包装器”包装它 - 就可以“插入”第一个参数,并且可以导出这个已经收到的函数。
我希望代码中的注释说明了使用什么以及如何使用。