diff --git a/src/collection/map.ts b/src/collection/map.ts index a51968f8..f12a66ab 100644 --- a/src/collection/map.ts +++ b/src/collection/map.ts @@ -10,6 +10,6 @@ interface Cash { fn.map = function ( this: Cash, callback: MapCallback ) { - return cash ( map.call ( this, ( ele: EleLoose, i: number ) => callback.call ( ele, i, ele ) ) ); + return cash ( concat.apply ( [], map.call ( this, ( ele: EleLoose, i: number ) => callback.call ( ele, i, ele ) ) ) ); }; diff --git a/src/core/variables.ts b/src/core/variables.ts index e05471b8..6453fd36 100644 --- a/src/core/variables.ts +++ b/src/core/variables.ts @@ -8,7 +8,7 @@ const doc = document, tbody = createElement ( 'tbody' ), tr = createElement ( 'tr' ), {isArray, prototype: ArrayPrototype} = Array, - {filter, indexOf, map, push, slice, some, splice} = ArrayPrototype; + {concat, filter, indexOf, map, push, slice, some, splice} = ArrayPrototype; const idRe = /^#[\w-]*$/, classRe = /^\.[\w-]*$/, diff --git a/test/modules/collection.js b/test/modules/collection.js index 45e01970..a1f9a0f3 100644 --- a/test/modules/collection.js +++ b/test/modules/collection.js @@ -236,6 +236,20 @@ describe ( 'Collection', { beforeEach: getFixtureInit ( fixture ) }, function () }); + it ( 'supports callbacks that returns multiple elements', function ( t ) { + + var mapped = $('
').map ( function () { + + return [document.head, document.body]; + + }); + + t.is ( mapped.length, 2 ); + t.true ( !!mapped.get ().find ( e => e === document.head ) ); + t.true ( !!mapped.get ().find ( e => e === document.body ) ); + + }); + }); describe ( '$.fn.slice', function ( it ) {