I have a JavaScript file which contains the following:
const api = {
call(type, url, data) {
console.log(type + "bar");
},
get(url, query) {
this.call("foo");
}
}
I'm wanting to be able to call api.get()
across multiple different files where necessary, but I'm having trouble importing this.
Loading the file alone through
import
gives me a ReferenceError when I attempt to access theapi
variable:import "services/api.js"; console.log(api);
Uncaught ReferenceError: api is not defined
Giving the import a name (of
api
) returns an Object, but it has no inner methods:import api from "../../services/api.js"; console.log(api); console.log(api.get);
Object {}
undefined
What am I doing wrong?