ded/bonzo — Issue #63: Return value confusion for stand-alone Bonzo
Author: rvagg
Created: 2012-01-08 10:11:28+00:00
State: open

These public functions that return something other than the container object all return vanilla arrays:

```js
bonzo.next()
bonzo.previous()
bonzo.detach()
bonzo.map()
bonzo.related()
```

And these public functions that all return something other than the container object all return a `Bonzo()` style array:

```js
bonzo.first()
bonzo.last()
```

So, for example, if you call `bonzo([el1, el2]).next()` you get `[el3, el4]` where they are the `nextSibling` elements for the original pair. But if you call `bonzo([el1, el2]).first()`, you get a `bonzo([el1])`.

For the other functions, they mostly operate through the internal `each()` which simply returns `this` so you get a `bonzo()` object like `first()` and `last()`. For the functions in the first category above, they operate through `bonzo.map()` which returns a fresh array, `[]`.

This doesn't matter so much for Ender because the bridge takes care of it but there are consistency issues for using Bonzo alone, chaining function calls is interrupted: `bonzo([el1, el2]).show().next().hide()` doesn't work because you're operating on a non-Bonzo-wrapped object after the `next()` call.

I'd love to fix this and submit a PR but perhaps it's intentional? My proposal would be to always return a Bonzo-wrapped array so you can chain your calls and everything is consistent. The only one that makes sense not to wrap is perhaps `map()` which could return arrays of pretty much anything depending on your callback function, but this would need to be documented in the README.