在 JavaScript 中充当未标记的道具。这叫什么,它是如何工作的?
Function as unlabeled prop in JavaScript. What is this called, and how does it work?
我今天看到这段代码,它做了我以前从未见过的事情。它有一个对象,它本身有一个未标记的 属性 是一个函数。
emails = {
type: EmailType,
args: { id: { type: GraphQLID } },
resolve(parentValue, args) {
const query = `SELECT * FROM "emails" WHERE id=${args.id}`;
return db.conn.one(query)
.then(data => {
return data;
})
.catch(err => {
return 'The error is', err;
});
}
}
}
我想知道更多关于这个的信息,但我不知道正确的关键词是什么,搜索 "function as property js" 只会产生非常明显的东西(即 {someProp: () => 42}
)。
我确定两者:
一个。如果我知道正确的关键词,那么学习更多就会很容易
乙。使这个关键词更容易找到的唯一方法是让某些人实际搜索到它。为此,我将包括一些额外的 SEO:
- 对象有功能但在 prop
- 对象内联函数
- 对象中的函数
- 对象有功能但不是道具
- 函数没有 propname
总之:
这叫什么,我在哪里可以找到更多相关信息?
编辑:获得文档链接。要表示的一件事是
之间的差异
// these are the same, I think
const eg1 = { someFn() {} }
const eg2 = { someFn: function() {} }
// this is different in scope... I think
const someFn = () => {};
const eg3 = { someFn };
{ method() { /*...*/ } }
等于:
{ method: function() { /*...*/ } }
我今天看到这段代码,它做了我以前从未见过的事情。它有一个对象,它本身有一个未标记的 属性 是一个函数。
emails = {
type: EmailType,
args: { id: { type: GraphQLID } },
resolve(parentValue, args) {
const query = `SELECT * FROM "emails" WHERE id=${args.id}`;
return db.conn.one(query)
.then(data => {
return data;
})
.catch(err => {
return 'The error is', err;
});
}
}
}
我想知道更多关于这个的信息,但我不知道正确的关键词是什么,搜索 "function as property js" 只会产生非常明显的东西(即 {someProp: () => 42}
)。
我确定两者:
一个。如果我知道正确的关键词,那么学习更多就会很容易
乙。使这个关键词更容易找到的唯一方法是让某些人实际搜索到它。为此,我将包括一些额外的 SEO:
- 对象有功能但在 prop
- 对象内联函数
- 对象中的函数
- 对象有功能但不是道具
- 函数没有 propname
总之:
这叫什么,我在哪里可以找到更多相关信息?
编辑:获得文档链接。要表示的一件事是
之间的差异// these are the same, I think
const eg1 = { someFn() {} }
const eg2 = { someFn: function() {} }
// this is different in scope... I think
const someFn = () => {};
const eg3 = { someFn };
{ method() { /*...*/ } }
等于:
{ method: function() { /*...*/ } }