The following code does not work as desired (jsFiddle):
function makeFoo(a, b) {
var foo = new Foo();
Foo.apply(foo, arguments);
return foo;
}
var Foo = function(a, b) {
console.log(
"This should be called once. "+
"a=\"" + a + "\", " +
"b=\"" + b + "\", "
);
this.a = a;
this.b = b;
}
Foo.prototype.go = function() {
console.log("a: " + this.a);
console.log("b: " + this.b);
};
var foo = makeFoo("Hello", "World");
foo.go();
Expected output:
This should be called once. a="Hello", b="World"
a: Hello
b: World
Actual output:
This should be called once. a="undefined", b="undefined"
This should be called once. a="Hello", b="World"
a: Hello
b: World