当我想知道Python中函数的参数数量和参数类型时,我只需使用函数help()来获取它们。但在javascript或nodejs中,很难知道函数的参数类型和参数数量。Javascript 中是否有类似于 Python 帮助的功能,或者是否有其他方式获取该信息?
采取下面的示例代码
var promise = new Promise(function(resolve, reject) {
const x = "geeksforgeeks";
const y = "geeksforgeeks"
if(x === y) {
resolve();
} else {
reject();
}
});
promise.
then(function () {
console.log('Success, You are a GEEK');
}).
catch(function () {
console.log('Some error has occured');
});
Run Code Online (Sandbox Code Playgroud)
上面的代码工作正常。但是,如果我只是执行作为参数传递给 Promise() 的函数,我会收到一条错误消息,指出resolve 不是函数。
(function(resolve, reject) {
const x = "geeksforgeeks";
const y = "geeksforgeeks"
if(x === y) {
resolve();
} else {
reject();
} })()
Run Code Online (Sandbox Code Playgroud)
如果我运行上面的代码,我会收到以下错误
Uncaught TypeError: resolve is not a function
Run Code Online (Sandbox Code Playgroud)
有人可以解释这是如何工作的吗?