2017-10-16 168 views
1

我指的是我的生成器方法module.exports但它的argumentsmodule数组不是被调用的函数。模块参数覆盖函数参数

const Promise = require('bluebird'); 

const inc = Promise.coroutine(function* (model, condition, fields, options = {}) {}); 

module.exports = { 
    inc: (model, condition, fields, options = {}) => { 
     //reveiving all the arguments fine 
     return inc.apply(null, arguments); //but "arguments" array contains the values of "module", not the function 
    } 
}; 

arguments阵列:

0 - require function 
1 - Module 
2 - file path 
3 - directory path 

回答

1

Arrow functions do not bind an arguments object

它应该是:

module.exports = { 
    inc: (...args) => inc(...args) 
}; 

除非出口直接导致与功能方面的问题,也可以只是:

module.exports = { 
    inc 
}; 
+0

我得到了它的工作,但我不明白的问题。你能解释你的第一行**箭头函数不绑定参数对象**吗? – Shaharyar

+0

'arguments'不能用于箭头来引用它们的参数,'arguments'指父函数作用域参数(在你的情况下是模块函数) - 与箭头中的this相似。被链接的参考文献解释了这一点。 – estus

+0

我明白'arguments'属于父函数范围*(链接中也有解释)*,但我不明白箭头函数不能/不能有'arguments'。如果箭头函数是父项,该怎么办?我只是检查了制作箭头函数parent并收到了'arguments'对象.. – Shaharyar