I've discovered this piece of code in the Meteor.js tutorial. It's ES2015:
Meteor.methods({
'tasks.insert'(text) {
check(text, String);
// Make sure the user is logged in before inserting a task
if (! this.userId) {
throw new Meteor.Error('not-authorized');
}
Tasks.insert({
text,
createdAt: new Date(),
owner: this.userId,
username: Meteor.users.findOne(this.userId).username,
});
},
});
And I'm curious about that way of defining functions. As we can see, Meteor.methods
is given an object as a parameter, and that object contains functions as its props' values. But what a heck is that:
'tasks.insert'(text) {
?? I expect 'tasks.insert' to be a string representing the prop name and that prop name should be mapped to a function that performs inserting. but why isn't it like
'tasks.insert': (text) => {
or
'tasks.insert': function(text) {
What a pattern is that and how does this can even be a valid JS?