epeli/underscore.string — Issue #56: underscore.string doesn't mix in nicely with underscore.js in Node.js
Author: nanodeath
Created: 2011-10-23 17:28:37+00:00
State: open

I'm not sure what the best way to solve this is, but this has been driving me bonkers...the problem is the check at the top of underscore.string for the _ variable doesn't actually work reliably. Here's the test case:

```javascript
var _ = require("underscore")
function Cat(){}
function Dog(){}
var cat = new Cat;
var dog = new Dog;
var animalsThatPurr = [cat];
console.log("Do dogs purr? " + _.include(animalsThatPurr, dog)); // prints false
_.mixin(require("underscore.string"));
console.log("Do they purr after including underscore.string? " + _.include(animalsThatPurr, dog)); // prints true
```

The problem is when underscore.string loads, _ will be undefined (since _ is scoped to the test file), so _.include (which was taken over by underscore.string) will fall back on to _.includes (also defined by underscore.string), which converts all/some of its args to strings, so you get a bunch of stringwise [Object object] comparisons.