Create a class that can be called directly without new
class View {
constructor() {
}
}
new View();
View()
Similar to this
new String("")
String("")
How can I do this?
Create a class that can be called directly without new
class View {
constructor() {
}
}
new View();
View()
Similar to this
new String("")
String("")
How can I do this?
What you are talking about is what's known as a factory function
https://medium.com/javascript-scene/javascript-factory-functions-with-es6-4d224591a8b1
class View{
constructor(){
}
static makeView() {
return new View();
}
}
const view1 = new View();
const view2 = makeView();
I don't think you can call it the exact same thing as your class though.