When the myClass
function returns a single string "hii", testClass.getDetails()
works fine:
function myClass(name, age) {
this.name = name;
this.age = age;
return "hii";
}
myClass.prototype.getDetails = function() {
return "mydetails";
}
var testClass = new myClass('aneesh', 27);
alert(testClass.getDetails());
But when I return an object in myClass
:
function myClass(name, age) {
this.name = name;
this.age = age;
return {};
}
I get an error:
testClass.getDetails is not a function
Why does that happen? In Javascript a string is also an object, right?