A declaration of a property with the name "name" is always an empty string, no matter how much I force (a hardcoded) a value into it. The weird part is, this only appears to be happening in Chrome and Firefox. IE works perfectly fine, and I didn't even intially built this for IE.
Here's a little snippet to reproduce the issue:
var fn = function() {
this.name = "Hello World"
this.foo = "bar"
}
// Create a blank function.
var obj = function() {};
// replacing the code below with 'var o = new fn()' doesn't make a difference.
var o = Object.create(fn.prototype);
fn.apply(o);
for (var i in o) {
// This line will print:
// name = Hello World
// foo = bar
console.log(i + ' = ' + o[i]);
// Apply them to the 'empty' function.
obj[i] = o[i];
}
console.log(obj.name); // prints ""
console.log(obj.foo); // prints "bar"
// Hardcode a value, just because I'm aggresive and frustrated.
obj.name = "test?"
console.log(obj.name); // still prints empty string :(
I'm not interested in hearing alternatives to the object construction, I just want to know why this particular implementation doesn't work in Chrome and FF while it does in all IE versions, including 11.