0

I have the following Javascript file, one.js:

function doSomething() {
    console.log("doing stuff");
}

I have another Javascript file, two.js, in which I want to call doSomething():

doSomething();

How can I achieve this? Note this code is for a browser extension so I cannot use html.

1

2 Answers 2

2

You have to import the function from one.js as below :
import doSomething from "one.js";

Then assign it to some variable of current object and use it.
this.doSomething = doSomething();

Sign up to request clarification or add additional context in comments.

Comments

0

you can use scripts as background and content script in extensions code, you can do something like that,

 "background": {
 "scripts": [ "js/sharedFunctions.js", "js/mainBackground.js" ]
 },
"content_scripts": [
  {
    "matches": ["*://*/*"],
    "js": ["js/sharedFunctions.js", "js/mainContentScript.js"]
  }
]

then functions of first file can be used in second as per order

2 Comments

At the end of question , it is mentioned ,"Note this code is for a browser extension so I cannot use html."
Oh sorry my mistake

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.