我有一個文件夾中的兩個文件 - index.js
和util.js
與他們的代碼庫如下意外變量
util.js中
let obj = {}
obj.sendTransaction =() => {
console.log(arguments);
return new Promise((resolve, reject) => {
// try {
// let data = ethFunction.call()
// resolve(data)
// } catch (e) {
// reject(e)
// }
});
}
module.exports = obj
在Index.js
,如果我通過參數addNewParticipant
或其變化那麼他們不會在參數調高對象util.js
,例如
const addNewParticipant = (foo, bar) => {
var ethFunction = myContract.addParticipant.sendTransaction
console.log(ethFunction);
EthUtil.sendTransaction()
}
const addNewParticipantTwo = (foo, bar) => {
var ethFunction = myContract.addParticipant.sendTransaction
console.log(ethFunction);
EthUtil.sendTransaction(ethFunction, foo, bar)
}
並將其稱爲addNewParticpant(1, 2)
和addNewParticpantNew(1, 2)
數字1和2不顯示在util函數的參數對象中。事實上,arguments對象保持相同,4個輸入描述的一些功能和文件node_modules
包括Bluebird
並index.js
基準本身
我的最終目的是
從傳遞函數
index.js
至util.js
傳遞未知數量的變量
調用傳遞的功能,並在承諾適用未知數量的變量它
包住整個事情,做一些數據驗證
理想arguments[0]
將是一個功能我會及格,另一個就是價值。然後我會用
var result = arguments[0].apply(null, Array().slice.call(arguments, 1));
如果有幫助,我想通過函數有一個可選的回調特徵
胖箭頭沒有自己的'this'或'arguments'對象。如果你想要這些,你將不得不使用「常規功能」。或者使用[rest參數](// developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/rest_parameters)'obj.sendTransaction =(fn,... args)=> {console.log (fn,args)}' – Thomas
請停止發送垃圾郵件標籤,這個問題與nodejs,原型或原型無關 – Thomas