Is there any case where a Constructor returns something on purpose and it still makes sense to new
it?
var Fn = function(){
return this.fn = function(){}
}
var a = new Fn()
var b = Fn()
I can't seem to find any difference between a
and b
from console, but just in case I missed something, are they identical? Apart from b
's side effect of adding fn
as a method to window
object. And if they're the same, does it mean that when a Constructor returns something, it's no longer a Constructor and shouldn't be new
ed?
Edit, the reason I'm asking is that I'm working with Coffee and Angular at the moment, while both seem to be pretty sensitive about return
, especially with providers. Do you have any best practises regarding this?