我正在使用NodeJS 0.10.13。我只是好奇,下面的代碼片段的行爲:Array.forEach/.map與path.resolve一起使用時返回錯誤
> var a = ['1','2','3']
undefined
> a.map(function(){return path.resolve(arguments[0])})
[ '/Users/user/1',
'/Users/user/2',
'/Users/user/3' ]
> a.map(path.resolve)
TypeError: Arguments to path.resolve must be strings
at exports.resolve (path.js:313:15)
> a.map(path.resolve.bind(path)))
TypeError: Arguments to path.resolve must be strings
at exports.resolve (path.js:313:15)
爲什麼是它的第二和第三map
調用返回一個錯誤,當陣列只有字符串?要在的NodeJS的源代碼中的相關行得到這樣的:
if (typeof path !== 'string') {
throw new TypeError('Arguments to path.resolve must be strings');
} else if (!path) {
continue;
}
這是沒有意義的,爲什麼參數不是字符串。有沒有人有任何線索?