I must have some sort of fundamental misunderstanding of how objects work in Javascript because I am unable to figure out why the following outputs what it does. You can see the jsfiddle of the following code here: http://jsfiddle.net/VivekVish/8Qvkn/1/
Note that is uses the getName function defined here: How do I get the name of an object's type in JavaScript?
Object.prototype.getName = function()
{
var funcNameRegex = /function (.{1,})\(/;
var results = (funcNameRegex).exec((this).constructor.toString());
return (results && results.length > 1) ? results[1] : "";
};
function ContentProvider()
{
}
function LessonProvider()
{
console.log(this.getName());
}
lessonProvider1 = new LessonProvider();
LessonProvider.prototype = new ContentProvider();
lessonProvider2 = new LessonProvider();
The above code outputs the following to the console:
LessonProvider
ContentProvider
But why isn't it LessonProvider in both cases and how can one make it LessonProvider in both cases?