What is going on behind the scenes here for each script. Assuming that I will be getsize() alot, is there any difference between the code:
Code 1:
function Size (width, height)
{
this.width = width;
this.height = height;
}
function getSize()
{
return new Size (0, 0);
}
Code 2
function getSize ()
{
return {width: 0; height: 0};
}
I think they are equivalent both in all senses but just wanted to check.
In the first code example you’re returning a named object called Size, in the second code you’re returning an anonymous javascript object. Thus you lose the Size objects constructor and prototype hindering you to extend all similar objects further.