Uncaught TypeError: x is not a function when Importing Factory Function
Uncaught TypeError: x is not a function when Importing Factory Function
我有一个名为 updateUI 的工厂函数,我正在将其导入 index.js。导入时,updateUI 的实例被识别,但是在尝试调用 updateUI 的方法时出现错误。
将所有代码放入 index.js 可以消除错误,但它仍然让我摸不着头脑。似乎只有在导入时才会出现问题。为什么该方法未被识别?
index.js
import '../../dist/output.css';
import { updateUI } from './display.js';
const test = updateUI('Daly City');
test.setBackground();
display.js
import { getWeather } from './apiCall';
const updateUI = async(location) => {
const res = await getWeather(location, process.env.apiKEY);
function updateCity() {
const city = document.querySelector('#location');
city.innerHTML = res.name;
};
function updateCurrentTemp() {
const currentTemp = document.querySelector('#current-temp');
const farenheit = Math.round((9/5)*(res.main.temp - 273) + 32);
currentTemp.innerHTML = farenheit;
};
function updateConditions() {
const condition = document.querySelector('#weather');
condition.innerHTML = res.weather[0].description;
};
function setBackground() {
const date = new Date();
let time = date.getTime();
console.log(time);
};
return { updateCity, updateCurrentTemp, updateConditions, setBackground }
};
export { updateUI };
@code 在评论中回答的问题。
我有一个名为 updateUI 的工厂函数,我正在将其导入 index.js。导入时,updateUI 的实例被识别,但是在尝试调用 updateUI 的方法时出现错误。
将所有代码放入 index.js 可以消除错误,但它仍然让我摸不着头脑。似乎只有在导入时才会出现问题。为什么该方法未被识别?
index.js
import '../../dist/output.css';
import { updateUI } from './display.js';
const test = updateUI('Daly City');
test.setBackground();
display.js
import { getWeather } from './apiCall';
const updateUI = async(location) => {
const res = await getWeather(location, process.env.apiKEY);
function updateCity() {
const city = document.querySelector('#location');
city.innerHTML = res.name;
};
function updateCurrentTemp() {
const currentTemp = document.querySelector('#current-temp');
const farenheit = Math.round((9/5)*(res.main.temp - 273) + 32);
currentTemp.innerHTML = farenheit;
};
function updateConditions() {
const condition = document.querySelector('#weather');
condition.innerHTML = res.weather[0].description;
};
function setBackground() {
const date = new Date();
let time = date.getTime();
console.log(time);
};
return { updateCity, updateCurrentTemp, updateConditions, setBackground }
};
export { updateUI };
@code 在评论中回答的问题。