I want to create simple plugin with ES6 using classes . but without using new keyword . it possible to return new instance from class automatically .
example :
class Rectangle{
constructor(x, y){
this.x = x,
this.y = y
}
eq(){
console.log('Result ' + this.x * this.y )
}
}
const myRect = new Rectangle(10, 10);
myRect.eq();
I want to use like this
Rectangle.eq(10, 10);
static eq(x, y) { return new this(x, y).eq(); }to achieve what you want, but unless there is more to it than you are showing, a class is unnecessary.