highwire/opensource-js-ImpactStory — pull request #2 by davidcmoulton (2013-07-26 02:27:56+00:00)
Title: Modified impactStory constructor to still work if invoked without 'new'

Sometimes the 'new' keyword is erroneously omitted when invoking a constructor. If so, 'this' within the constructor function refers to the global object, and not the (expected) object returned by the constructor. Then things break.

This commit bulletproofs the impactStory constructor against being invoked without 'new'. Before the constructor does anything else, it checks whether 'this' is an instance of impactStory (expected), and if it's not, it internally invokes "new impactStory()", thus setting 'this' to the expected value.