我有一个快速的 javascript 问题。
说我有RootFile.js
import UserApi from './UserApi'
export default class RootFile {
get userApi() {
return UserApi;
}
};
然后我得到了UserApi.js
import Auth from './auth';
import Profile from './profile';
const merged = {
...new Auth,
...new Profile
}
export default merged;
然后我得到了单独的功能文件,比如auth.js
or profile.js
。
auth.js
export default class Auth{
authLog(){
console.log("DONE");
//Gotta find a way to run this.
}
}
profile.js
export default class Profile{
profileLog(){
console.log("DONE");
//Gotta find a way to run this.
}
}
现在我希望能够调用:
import RootFile from './RootFile'
RootFile.userApi.profileLog();
//and
RootFile.userApi.authLog();
我无法让它工作,RootFile.userApi
is a typeof object
,但authLog
is undefined
. 我究竟做错了什么?