Is there any reason why the constructor function doesn't normalize its inputs?
If it did, it would save a hell of a lot of bonzo.create()s.
Anyway, it came up in IRC, and I was wondering if anyone else might be able to provide insight. If there's no good reason not to, then I'd like to propose that normalization get added...
Cheers!
can you give an example? there's probably a very good reason — if not simply for the sake of speed, and that doing this via Ender would do it anyway.
@ded I was discussing this with @adlwalrus and I couldn't come with a good reason that bonzo() isn't more clever and wondered if there was something I was overlooking.
bonzo(bonzo.create('<p>')).appendTo('#something') // unnecessarily awkward
The manip methods are clever enough to normalize() & query(), the constructor should probably be too, for Bonzo stand-alone. There's already a typeof elements == 'string' check in there but it doesn't do anything sensible.
That, and the fact that bonzo.create() doesn't return a Bonzo collection.
hmmm.... i suppose so... we'd have to bump up the package a minor version tho
and update a few tests...
Anyone wanna do it? If not, then anyone wanna coach me through doing it?
Well that was silly... how does this look? https://github.com/ded/bonzo/pull/103
(I had a look over the tests to see if there were any I could clearly identify as needing to be updated, but it appears not.)
(Also, I'm still not sure what @rvagg was talking about with query() after poking around in the sources. I assume it has to do with being able to pass a selector into the constructor, but I'm not sure.)