This repository has been archived by the owner on Sep 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
remote的写法支持es6的class么 #869
Comments
es6 的支持需要研究一下,我这里先记一下 |
遇到同样的问题,求解 |
Remote不支持。Handler支持。 class Super {
calc() {
return 1;
}
}
class Child extends Super {
run() {
return this.calc() * 2;
}
}
//这是我们真正的remote handler
class Some extends Child {
login(name, pwd, next) {
next(null, {
key: this.calc(),
value: this.run()
});
}
}
// 创建一个function来实现支持
const Other = function () {
}
//使用Object.create来支持继承链, 否则Some里面是调用不到calc和run方法的. 如果你要copy的类是孤类, 这一步可以不做
Other.prototype = Object.create(Some.prototype);
//复制Some类中的自有方法. 不支持使用Object.defineProperty
Object.getOwnPropertyNames(Some.prototype).forEach(key => {
Other.prototype[key] = Some.prototype[key];
})
//替换构造器
Other.prototype.constructor = Other;
module.exports = () => new Other(); Remote和Handler都通过 |
如果能提供全套的es6支持就好了,现在已经不习惯callback了
在 2017-07-30 18:54:16,"Sean" <notifications@github.com> 写道:
Remote不支持。Handler支持。还在查。
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@redelva
在
注意, 错误(next不会被执行, 导致
正确(手动调用
或者
如果需要将session中的方法 promisify.js
app.js
调用
|
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
我在authRemote这样写
这样写rpc调用的时候,authRemote对象就是空的,拿不到auth方法。
但是改回prototype却可以。这是什么原因?
The text was updated successfully, but these errors were encountered: