Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
996 views
in Technique[技术] by (71.8m points)

import - How do I resolve a problem with a function Imported from a different file in JavaScript?

im struggling with Javascript, specifically with a module. I recently created a file named Input.js wich is substantially my module, containing some function that i recall in another file located in the same directory.

the structure i created is like the one below

file input.js

export function foo(param){return hello;}

file main.js

import {foo} from './input.js';

function bar(param){ 
  foo(param);
};

file index.hmt

<script src="main.js" type="module">
<button onclick="bar(this)"/>

the problem is that when i click the button javascript create an error:

Uncaught ReferenceError: foo is not defined at HTMLElement.onclick

but i've already created the function.

Can anyone help me to figure out what i am doing wrong ? thanks to everyone that can help me.

question from:https://stackoverflow.com/questions/65862739/how-do-i-resolve-a-problem-with-a-function-imported-from-a-different-file-in-jav

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...