Comments (6)
from pinus.
Sorry, 我实际代码有写new, 贴上来时候漏了,已编辑上
export default function只有子类写了,基类只有在constructor里用super调用
from pinus.
我先看一下pinus-rpc/utils/utils.ts里的listEs6ClassMethods方法,应该是这个没把父类方法过滤出来
from pinus.
class BaseHandler {
foo() {
}
}
class MyHandler extends BaseHandler {
bar() {
}
}
function listEs6ClassMethods(objInstance: { [key: string]: any }) {
if (objInstance.prototype && objInstance.prototype.constructor === objInstance) {
let names: string[] = [];
let methodNames = Object.getOwnPropertyNames(objInstance.prototype);
for (let name of methodNames) {
let method = objInstance.prototype[name];
// Supposedly you'd like to skip constructor
if (!(method instanceof Function) || name === 'constructor') continue;
names.push(name);
}
return names;
} else {
let names: string[] = [];
let methodNames = Object.getOwnPropertyNames(Object.getPrototypeOf(objInstance)).concat(Object.getOwnPropertyNames(objInstance));
for (let name of methodNames) {
let method = objInstance[name];
// Supposedly you'd like to skip constructor
if (!(method instanceof Function) || name === 'constructor') continue;
names.push(name);
}
return names;
}
}
let ret = listEs6ClassMethods(new MyHandler());
console.log(ret);
print:[ 'bar' ]
from pinus.
文件 pinus/packages/pinus-rpc/lib/util/utils.ts
function listEs6ClassMethods(objInstance: { [key: string]: any }) {
if (objInstance.prototype && objInstance.prototype.constructor === objInstance) {
let names: string[] = [];
let methodNames = Object.getOwnPropertyNames(objInstance.prototype);
for (let name of methodNames) {
let method = objInstance.prototype[name];
// Supposedly you'd like to skip constructor
if (!(method instanceof Function) || name === 'constructor') continue;
names.push(name);
}
return names;
} else {
let names: string[] = [];
let methodNames = Object.getOwnPropertyNames(Object.getPrototypeOf(objInstance)).concat(Object.getOwnPropertyNames(objInstance));
for (let name of methodNames) {
let method = objInstance[name];
// Supposedly you'd like to skip constructor
if (!(method instanceof Function) || name === 'constructor') continue;
names.push(name);
}
return names;
}
}
具体的代码是这个 现在有事不能研究了。
我测试了一下,的确不能获取到父类的方法。
class BaseHandler {
protected app;
constructor(app) {
this.app = app;
}
public async who(msg, session) {
return { myname: "this.constructor.name" };
}
}
class MyHandler extends BaseHandler {
constructor(app) {
super(app);
}
public async myMethod(msg, session) {
return { msg: 'this is my method' };
}
}
console.log(listEs6ClassMethods(MyHandler))
let ins = new MyHandler(null)
console.log(listEs6ClassMethods(ins))
console.log(ins.who(null,null))
console.log(Object.getPrototypeOf(ins).constructor.prototype)
// 这一句才可以获取到父类的方法
console.log(Object.getPrototypeOf(ins.constructor.prototype))
你可以自己copy一下 dictionary组件 自己处理一下这个情况
用这名代码替换掉框架自带的 dictionary.
pinus.components.dictionary = DictionaryComponent;
from pinus.
@whtiehack 感谢
from pinus.
Related Issues (20)
- 示例工程中运执行npm-install.bat报错怎么处理 HOT 3
- pinus-admin-web不能正常显示监控数据 HOT 4
- 解决一下严格模式问题
- protobuf支持map吗? HOT 11
- 请问指南中完整的mmo游戏demo在哪里 HOT 1
- pinus-robot 启动master节点连接报错 {"code":5,"message":"Unsupported protocol version"} HOT 2
- [pinus-admin] pinus-admin客户端connect问题。 HOT 2
- 请问下如何服务器和客户端之间的消息如何启用 compressGzip 进行压缩 HOT 2
- 有人了解colyseus这个游戏框架吗?有跟pinus对比过吗
- pinus-logger模块打印对象时,显示[object object]的问题 HOT 4
- 客户端build.js和服务器怎么感觉没有适配好? HOT 4
- 有没遇到过这种情况?master请求其他实例失败,下面是报错日志,有新的connector服务加入,通知其他connector好像失败了 HOT 2
- 其他服务与master断开连接后,会触发master不断的重连,这个重连好像不会停止,还是说有什么地方可以配置 HOT 4
- connector性能瓶颈 HOT 8
- jsclient-websocket, request的第128个请求得不到返回 HOT 1
- app.rpcInvoke is not a function HOT 1
- 启动不了,报错 (`node:stream/web`) HOT 4
- 快速入门有些操作会报错,不知nodejs版本要求多少 10.x,14.x,20.x都试过 HOT 3
- npm 上的版本太老了,能不能发个最新版 HOT 2
- 关于业务逻辑的热更思考 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pinus.