Your example differs from the example you provided in that you have params and the example doesn't.
When you don't call the constructor (see Stephan's example) with param values, the object is created without any params.
The difficulty seems to be that you are expecting new function to return a constructor, when it's actually returning the object that results from the constructor.
In modern JS, you wouldn't see code like this. As this seems to be using object-oriented techniques, you'd see the new class syntax being used. Alternatively, object-oriented approaches would be tossed out the window in favor of functional techniques.
peter tong wrote:why
new function(value) { /* whatever */ }
act like
new function(value) { /* whatever * }()
?
It's just one of the quirks of JavaScript. JavaScript also allows you to call a function with fewer arguments than there are parameters. The parameters will then have an undefined value. In general, you should not rely on this behavior.
so I must pass the parameter value immediately after the constructor definition.
Correct.
I have gone to look for myself. If I should return before I get back, keep me here with this tiny ad:
a bit of art, as a gift, the permaculture playing cards