【发布时间】:2018-09-28 04:20:28
【问题描述】:
我在GraphQL-related post 中发现了以下代码。 为什么fields参数的大括号外面有括号,这是什么意思?
var PersonType = new GraphQLObjectType({
name: 'Person',
fields: () => ({
name: { type: GraphQLString },
bestFriend: { type: PersonType },
})
});
以下是我知道的函数表达式/声明:
标准命名函数
function sayHello() {
alert("hello!");
};
ES6 匿名函数
() => {
alert("hello!");
};
自调用函数
(function sayHello() {
alert("hello!");
})();
自调用 ES6 匿名函数
(() => {
alert("hello!");
})();
据我所知,字段函数不符合上述任何一项。
【问题讨论】:
-
阅读the documentation 总是有用的。
-
啊,明白了。 @Teemu 感谢您的链接。我现在在“高级语法”下看到它。发现将我的问题用文字传达给 Google 有点困难,但现在很明显我应该更深入地研究箭头函数。
标签: javascript function