A friend recently sent me a question via twitter, asking for some code review. He was wondering why he had a constructor function that created a new object and returned that object, instead of allowing the constructor function to return its own object instance.
The code in question is for a game, where he has a Background object type that returns an instance of an object. In his questions, he wanted to know if he needed the extra “new” keyword for the Background function. He also wanted to know why the code was set up this way and what benefit it may have.
In this quick Q&A episode, you'll see the above code disassembled and put back together, explaining what is happening along the way. You'll learn when you do and don't need the “new” keyword for the Background function. And you'll see when and why you may want to set up the code in the manner shown in this example; what advantages this code structure has, and for what purpose.
Want To Know More?