Consider the code below. The d1
object so created, does not have name
property but why ? However, if I remove the setting of prototype as function object, things works fine. please note that below code is deliberately written like that to test how JS reacts !
function Dog(name){
this.name = name;
}
// Notice that I am putting function object as prototype
Dog.prototype = function(){}
var d1 = new Dog("happy");
console.log(d1.name); //gives empty string
console.dir(d1); // `d1` does not have name property
console.log(d1 instanceof Dog);// returns true ??