gpt4 book ai didi

javascript - 父作用域中函数的参数

转载 作者:行者123 更新时间:2023-12-03 07:50:44 25 4
gpt4 key购买 nike

我正在关注本教程 http://www.angular-meteor.com/tutorials/socially/angular2/meteor-methods

所以有:

import {Parties} from './parties';

function getContactEmail(user: Meteor.User): string {
if (user.emails && user.emails.length)
return user.emails[0].address;

return null;
};

Meteor.methods({
invite: function(partyId: string, userId: string) {
check(partyId, String);
check(userId, String);

let party = Parties.findOne(partyId);

if (!party)
throw new Meteor.Error('404', 'No such party!');

if (party.public)
throw new Meteor.Error('400', 'That party is public. No need to invite people.');

if (party.owner !== this.userId)
throw new Meteor.Error('403', 'No permissions!');

if (userId !== party.owner && (party.invited || []).indexOf(userId) == -1) {
Parties.update(partyId, { $addToSet: { invited: userId } });

let from = getContactEmail(Meteor.users.findOne(this.userId));
let to = getContactEmail(Meteor.users.findOne(userId));

if (Meteor.isServer && to) {
Email.send({
from: 'noreply@socially.com',
to: to,
replyTo: from || undefined,
subject: 'PARTY: ' + party.name,
text: `Hi, I just invited you to ${party.name} on Socially.
\n\nCome check it out: ${Meteor.absoluteUrl()}\n`
});
}
}
}
});

invite(user: Meteor.User) {
this.call('invite', this.party._id, user._id, (error) => {
if (error) {
alert(`Failed to invite due to ${error}`);
return;
}

alert('User successfully invited.');
});
}

我无法理解(error) => {,错误值从何而来?

最佳答案

在 ES6 中 (args) => { 是定义函数的简写方式 read more

所以

invite(user: Meteor.User) {
this.call('invite', this.party._id, user._id, (error) => {
if (error) {
alert(`Failed to invite due to ${error}`);
return;
}

alert('User successfully invited.');
});
}

相同
invite(user: Meteor.User) {
this.call('invite', this.party._id, user._id, function(error){
if (error) {
alert(`Failed to invite due to ${error}`);
return;
}

alert('User successfully invited.');
});
}

关于javascript - 父作用域中函数的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35001290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com