Answer the question
In order to leave comments, you need to log in
How to instantiate a JS class in a document?
Hello.
I use:
"@babel/preset-env": "^7.6.3",
"babel-loader": "^8.0.6",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.9"
class MyClass {
constructor(){ this.init()}
init () {}
}
Answer the question
In order to leave comments, you need to log in
Webpack creates an isolated scope for each module. You need to manually put your class into the global object:
class MyClass {
constructor(){ this.init()}
init () {}
}
// например вот так:
window.MyClass = MyClass;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question