When trying executing the two following code blocks separately: The first one:
function Hallo() {
}
var some_obj = {
name: "Fred",
age: 23,
}
Hallo.prototype = some_obj;
var obj = new Hallo();
obj.constructor;
And the second one:
function Hallo() {
}
Hallo.prototype.name = 'Khanh';
Hallo.prototype.age = 23;
var obj = new Hallo();
obj.constructor;
I got the result in firebug's console is "Object{}" for the first and "Hallo()" for the second. While the second one is pretty simple to understand but the first one is really odd. Because as I know the constructor of the obj Object in the first one is still the same (that is Hallo() function). However I got Object() function in result. I really cann't understand why. Could you help me with it? Thank you!
prototypein the first example, but in the second you're only adding two new properties.constructoris overwritten by the constructor of your object when you overwrite the entire prototype.