What is this JavaScript dependency?

I went 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, ...);
  ...
};
+4
source share
1 answer

This means that you can use it with newor without a keyword .

eg:.

var comp = new MyCompiler();

or

var comp = MyCompiler();

If you call it as a function, it will call itself with a keyword newand return an instance.

+8
source

All Articles