请解释这个JavaScript语言结构:JavaScript参数映射()函数
cursor => cursor.map(doc => doc._key)
在这种情况下
collection.all().then(
cursor => cursor.map(doc => doc._key) // this line
).then(
keys => console.log('All keys:', keys.join(', ')),
err => console.error('Failed to fetch all documents:', err)
);
不了解doc => doc._key
作为参数传递给map()
功能。为什么它不适用于doc => { key: doc._key, name: doc.name}
?
看看术语箭头功能,这将回答你的问题。 – Christos
谢谢Christos。我今天花了两个小时搜索,不知道他们被称为箭头函数。 –