Question

With FileUtils, do we have to use the the new word before it?

var f = new FileUtils.File(mypath);

Can't we just do:

var f = FileUtils.File(mypath);
Était-ce utile?

La solution

With the current Firefox version you can simply call FileUtils.File() as a function and you will get the same result. However, this is an implementation detail - the documentation clearly says that FileUtils.File() is a constructor and should be used as such, with the new keyword. So while you can use it as a function, you cannot really rely on this behavior - it might stop working if the implementation changes in future. More importantly, logically this is a constructor that creates a new object, using it as such makes the code easier to understand.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top