03-19-2018 12:14
03-19-2018 12:14
import document from "document"; var myRect = document.getElementById("myRect"); myRect.onclick = function(e) { console.log("click"); }
The above code works in index.js. What import or other statement do I need to have in index.js for it work if I want to move the code to another file?
Answered! Go to the Best Answer.
03-19-2018 22:32
03-19-2018 22:32
If you want to put that in a separate file, then you need to import that other file back into index.js.
// index.js import * as blah from "./blah";
blah.initialize();
// blah.js
import document from "document";
export function initialize() {
var myRect = document.getElementById("myRect");
myRect.onclick = function(e) {
console.log("click");
}
}
03-19-2018 22:32
03-19-2018 22:32
If you want to put that in a separate file, then you need to import that other file back into index.js.
// index.js import * as blah from "./blah";
blah.initialize();
// blah.js
import document from "document";
export function initialize() {
var myRect = document.getElementById("myRect");
myRect.onclick = function(e) {
console.log("click");
}
}