And these public functions that all return something other than the container object all return a Bonzo() style array:
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.
These public functions that return something other than the container object all return vanilla arrays:
And these public functions that all return something other than the container object all return a
Bonzo()
style array:So, for example, if you call
bonzo([el1, el2]).next()
you get[el3, el4]
where they are thenextSibling
elements for the original pair. But if you callbonzo([el1, el2]).first()
, you get abonzo([el1])
.For the other functions, they mostly operate through the internal
each()
which simply returnsthis
so you get abonzo()
object likefirst()
andlast()
. For the functions in the first category above, they operate throughbonzo.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 thenext()
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.