javascript - Transform a lodash/underscore collection in a jQuery object (chaining) -
i seamlessly wrap lodash collection in jquery object. right i'm saving lodash output in variable , feeding jquery:
//simplified code var els = [document.getelementbyid('a'), document.getelementbyid('b')]; els = _(els) .map(dostuff) .map(domorestuff); var $els = $(els);
but chain instead:
//pseudo code _(els) .map(dostuff) .map(domorestuff) .jqueryfy() //this magic method, missing .show() //jquery method, right away
i thought possible tap
, doesn't change collection.
_(els) .map(dostuff) .map(domorestuff) .tap(function(array) { return $(array); }) //doesn't return jquery object .show()
this should using mixin
jquery
constructor take array of dom elements:
_.mixin({jqueryfy: jquery}, {chain:false});
notice jquery support basic collection manipulation functions, could've written example as
$("#a, #b").map(dostuff).map(domorestuff).show();
Comments
Post a Comment