Javascript 将'meteor.method'类型绑定到普通对象
这听起来可能很奇怪,但我有一门课。当我创建这个类时,我想生成很多meteor方法Javascript 将'meteor.method'类型绑定到普通对象,javascript,meteor,Javascript,Meteor,这听起来可能很奇怪,但我有一门课。当我创建这个类时,我想生成很多meteor方法 Robot = class RobotServer extends RobotBase { // ... not terribly important // want to make this run as if it were a meteor method send(command) { if (Roles.userIsInRole(this.userId, 'operator', this
Robot = class RobotServer extends RobotBase {
// ... not terribly important
// want to make this run as if it were a meteor method
send(command) {
if (Roles.userIsInRole(this.userId, 'operator', this._id)) {
this._sockets.get('commands').write(`${command}\r`);
}
}
}
我想把它暴露出来,就好像它是一种流星方法一样。也就是说,在我的客户身上,我可以做如下事情:
Baymax = new Robot();
Baymax.send('message "I am Baymax, your personal health care companion"', function (err, result) {
console.log('command successfully sent.')
});
这在meteor中是可能的吗?你能解释一下你想要实现什么吗?这些实例“存在”在哪里?为什么有许多方法而不是一个解释命令的方法?我想把
this.userId
,this.connection
,以及所有绑定到Meteor.method
的实例绑定到这些函数中。你能解释一下你想实现什么吗?这些实例“存在”在哪里?为什么有许多方法而不是一个解释命令的方法?我想把this.userId
,this.connection
,以及所有绑定到Meteor.method
的实例绑定到这些函数。