cheeriojs/cheerio — pull request #542 by jugglinmike (2014-07-23 23:28:38+00:00)
Title: Alter "loaded" functions to produce true instances 

In preparation for this change, I re-organized the tests for `Cheerio.load`. That's the first commit--pretty boring.

The second commit is where it's at. Message:

> A common use case for this library is to generate a factory function
> based on document markup via the static method `Cheerio.load`:
>
> var $ = cheerio.load(aStringOfMarkup);
>
> ...the resulting function can be used in much the same way as the
> Cheerio (and jQuery) function itself. A notable exception is the
> inheritance structure of the instance:
>
> $('div') instanceof $; // <-- false
>
> This forces users to rely on a non-standard approach for determining the
> type of a selection:
>
> 'cheerio' in $('div'); // <-- true
>
> Modify `Cheerio.load` to return a true constructor function--one whose
> instances are instances both of the constructor itself and the `Cheerio`
> function.
>
> In addition, this change slightly improves efficiency in some use
> cases. When a "loaded" function is invoked with the `new` operator, the
> generated instance is used directly (instead of being discarded in favor
> of a new instance of the Cheerio function).