In terms of JavaScript, they're not the same. In terms of require()
as a function? It seems so, but I'd still advise against doing it.
Using new
does a lot under the hood. require()
will be affected by the use of new
, as it's internal value of this
will change.
var foo = {
path: '/foo/bar/',
require: function (module) {
console.log(this.path + module);
}
};
foo.require('baz'); // logs /foo/bar/baz
new foo.require('trev'); // logs undefinedtrev
Currently require()
seems not to use this
at all (as it's behaviour doesn't change whether you change the value of this or not). However, this isn't guaranteed to be the case in the future; it isn't documented.
TL;DR: don't use it.