Formed an object 'myclass' in my js file like this:
var myclass = function(){
this.m1 = function(){
return "THis is m1 of myclass"
};
return "this is myclass";
}
myclass.prototype.mp1 = function(){
return "this is mp1 of myclass"
}
now i do this:
var a = new myclass();
var b = new myclass;
Q1- I dont see any difference between the behaviors of these two. Please explain the reason.
Q2 - When I do - console.log(a), i expect to get "this is myclass" in console, but instead I see [object object].
Q3 - If I return an object from the constructor of 'myclass'(eg - return {x:1}), then I cannot use 'm1' or 'mp1' anymore from the instances of 'myclass'.
Q4 - Comparing this with Date class of window object, this is totally different behavior. If a = new Date(), then i see value of 'a' as a date although the type is an object, and this points to my next question.
Q5 - The date class returns a date which looks like a string in DOM but the 'typeof' of the instance of date class is an object. Why's that?
Sorry for posting so many questions at once, but it would be nice if I get answers for all questions as I think they are related.
This question is not about a particular question from the above 5. But combination of all. As I have to know the return type, comparison between myclass() and myclass, and comparison between myclass() and Date()/predefined window objects.