合并2个班级 [英] Merging 2 classes
本文介绍了合并2个班级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想合并2个类或将所有方法从1个类添加到另一个类。将来它将是更多的类而不仅仅是一个(ContainerClient)类。
I want to merge 2 classes or add all methods from 1 class to another. In the future It will be the more classes than just a (ContainerClient) class.
客户端
和 ContainerClient
我试过这个,但我认为它可以更容易完成。
I tried this but I think It can be done even easier.
for (var a of Object.getOwnPropertyNames(ContainerClient.prototype)) {
Client.prototype[a] = ContainerClient.prototype[a];
}
原则: ContainerClient
取决于客户
class Data {
constructor () {
}
}
Client.js
Client.js
class Client extends Data {
me () {
return {
id: '1',
};
}
}
Container.js
Container.js
class Container extends Data {
containers () {
return [
{
clientId: '1',
id: '2',
},
{
clientId: '2',
id: '3',
},
];
}
}
ContainerClient.js
ContainerClient.js
class ContainerClient extends Data {
containers () {
return {
clientId: '1',
id: '2',
};
}
}
- > <$ c $之前的Client.js c> export < -
--> Client.js before export
<--
这篇关于合并2个班级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文