我想我的问题可能是js的问题。我有两个班
Url
和
QueryVars
. 我想要
能够调用
QueryVars公司
,好像我延伸了
从
QueryVars公司
. 所以我做了这样的事情:
export default class Url {
constructor()
{
this.queryVars = new QueryVars();
console.log(this.queryVars);
for(let x in this.queryVars)
{
console.log(x); // this never gets fired
if(typeof this.queryVars[x] == "function")
{
this[x] = this.queryVars[x].bind(this.queryVars);
}
}
}
}
default class QueryVars {
init()
{
/* do something */
}
getQS(key)
{
/* do something */
}
getPage(key)
{
/* do something */
}
}
问题是
console.log(x)
不会被解雇。我无法找回
this.queryVars
Url.constructor
并绑定这些对象的更多方法,这样就好像我在实现多重继承,或者用其他类组成一个新类。这样我就可以:
do url.getQS() instead of url.queryVars.getQS()
do url.getIP() instead of url.ip.getIP()
etc...
我上面的代码是基于我在这个问题中所学到的:
Is there a way to print all methods of an object in javascript?