Now I know this might be a stupid question, but I need to improve my understanding of the language. So first, please have a look at the simple code:
JS:
function Blog(body , date){
this.body = body;
this.date = new Date(date);
}
Blog.prototype.toString = function(){
return '[' + (this.date.getMonth() + 1) + '/' + this.getDate() + '/' + this.getFullYear() + ']' + this.body;
};
Now, we humans can clearly see that there is an object constructor for the Blog
object, and there is a function that is owned by the Blog
class. Now, end of the day, the constructor is still a function
, a function which is written like any other function: same syntax, same kind of arguments etc.
Now here is my question: According to this, every function reference(which in this case, is Blog
) can be a class. Is it true or not? And if that is not true, how does javascript know that Blog
is a class and not just the reference to a function?
NOTE: I hope I made my point clear. If not, please tell me in the comments.