javascript - 访问作为参数传递的函数的参数
问题描述
我有一个反应组件,我需要验证其中一个道具应该是具有某种类型参数的函数。
我已经在我的设置中使用了道具类型,所以我虽然自定义验证器函数也可以帮助我验证这一点。
这就是我试图验证道具的功能签名的方式
children: (props, propName, componentName) => {
let error;
const prop = props[propName];
if (typeof prop !== "function") {
error = new Error("expected children to be a function");
}
// console.log(prop.length);
if (prop.length === 0) {
console.log(prop.length);
error = new Error("expected children to be a function with 1 argument");
}
// don't know how to verify the type of arguments
// can't use prop.arguments in strict mode
return error;
}
关于如何访问在 children 道具中传递的函数的参数的任何指针,然后验证它是否是typeof 'boolean'
?
解决方案
推荐阅读
- flutter - Flutter 中的 CSS 格式化
- mysql - 使用mysql将选择请求结果转换为nodejs中的数组
- c++ - 如何将结构转换为无符号字符,反之亦然?
- swift - 错误:“某些视图”类型的值没有成员“中风”
- swift - 为什么这些简单的 Metal GPU 计算内核比 CPU 实现慢或相等?
- c++ - 在不运行程序的情况下获取 constexpr
- r - 在循环中创建对象并将其输入到函数中
- r - 我无法从这个管道操作中得到标准偏差
- python - Matplotlib 投影 3d 级别问题
- android - E/flutter(16289):[错误:flutter/lib/ui/ui_dart_state.cc(177)]未处理的异常:SocketException:套接字已关闭