I was going through broccoli plugins and I see this line a lot. What is it used for?
function MyCompiler (arg1, arg2, ...) {
if (!(this instanceof MyCompiler)) return new MyCompiler(arg1, arg2, ...);
...
};
That is so that you can use it with or without the new
keyword.
E.g.:
var comp = new MyCompiler();
or:
var comp = MyCompiler();
If you call it as a function, it will call itself with the new
keyword and return the instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With