jimfog Posted December 8, 2011 Share Posted December 8, 2011 As stated in the tutorials you can create an object either by using a direct instance of it or a function constuctor. What are the reasons for using the function constructor method to create an object-what it offers that the direct method does not? Why should we use it? I just want to hear some opinions on the matter. Link to comment Share on other sites More sharing options...
thescientist Posted December 8, 2011 Share Posted December 8, 2011 using a function constructor will afford you the ability to reuse the object by being able to spawn multiple instances of it (using the new keyword. This method is an attempt to bring OOP/Class based programming to JS given it's desire to be a prototypal based language. If you wanted to create multiple People objects for an application, then this might be an approach to consider. If you were just in the need of creating a Singleton, then a direct instance would suffice. Also note that in this case, we could be referring to it as an object literal. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.