|
482 | 482 |
|
483 | 483 | /** Reusable iterator options for `invoke`, `map`, `pluck`, and `sortBy` */ |
484 | 484 | varmapIteratorOptions={ |
485 | | -'init':'', |
| 485 | +'init':false, |
486 | 486 | 'beforeLoop':{ |
487 | 487 | 'array':'result = Array(length)', |
488 | 488 | 'object':'result = '+(isKeysFast ?'Array(length)' :'[]') |
|
672 | 672 | * useStrict - A boolean to specify whether or not to include the ES5 |
673 | 673 | * "use strict" directive. |
674 | 674 | * |
675 | | - * args - A string of comma separated arguments the iteration function will |
676 | | - * accept. |
| 675 | + * args - A string of comma separated arguments the iteration function will accept. |
677 | 676 | * |
678 | 677 | * init - A string to specify the initial value of the `result` variable. |
679 | 678 | * |
|
691 | 690 | *@returns {Function} Returns the compiled function. |
692 | 691 | */ |
693 | 692 | functioncreateIterator(){ |
694 | | -varobject, |
695 | | -prop, |
696 | | -value, |
697 | | -index=-1, |
| 693 | +varindex=-1, |
698 | 694 | length=arguments.length; |
699 | 695 |
|
700 | 696 | // merge options into a template data object |
701 | 697 | vardata={ |
702 | 698 | 'bottom':'', |
| 699 | +'hasDontEnumBug':hasDontEnumBug, |
| 700 | +'isKeysFast':isKeysFast, |
| 701 | +'noArgsEnum':noArgsEnum, |
| 702 | +'noCharByIndex':noCharByIndex, |
| 703 | +'shadowed':shadowed, |
703 | 704 | 'top':'', |
704 | | -'arrayBranch':{'beforeLoop':''}, |
705 | | -'objectBranch':{'beforeLoop':''} |
| 705 | +'useHas':true, |
| 706 | +'useStrict':isStrictFast, |
| 707 | +'arrayBranch':{}, |
| 708 | +'objectBranch':{} |
706 | 709 | }; |
707 | 710 |
|
708 | 711 | while(++index<length){ |
709 | | -object=arguments[index]; |
710 | | -for(propinobject){ |
711 | | -value=(value=object[prop])==null ?'' :value; |
| 712 | +varobject=arguments[index]; |
| 713 | +for(varpropinobject){ |
| 714 | +varvalue=object[prop]; |
712 | 715 | // keep this regexp explicit for the build pre-process |
713 | 716 | if(/beforeLoop|inLoop/.test(prop)){ |
714 | 717 | if(typeofvalue=='string'){ |
715 | 718 | value={'array':value,'object':value}; |
716 | 719 | } |
717 | | -data.arrayBranch[prop]=value.array||''; |
718 | | -data.objectBranch[prop]=value.object||''; |
| 720 | +data.arrayBranch[prop]=value.array; |
| 721 | +data.objectBranch[prop]=value.object; |
719 | 722 | }else{ |
720 | 723 | data[prop]=value; |
721 | 724 | } |
|
724 | 727 | // set additional template `data` values |
725 | 728 | varargs=data.args, |
726 | 729 | firstArg=/^[^,]+/.exec(args)[0], |
727 | | -init=data.init, |
728 | | -useStrict=data.useStrict; |
| 730 | +init=data.init; |
729 | 731 |
|
730 | 732 | data.firstArg=firstArg; |
731 | | -data.hasDontEnumBug=hasDontEnumBug; |
732 | 733 | data.init=init==null ?firstArg :init; |
733 | | -data.isKeysFast=isKeysFast; |
734 | | -data.noArgsEnum=noArgsEnum; |
735 | | -data.shadowed=shadowed; |
736 | | -data.useHas=data.useHas!==false; |
737 | | -data.useStrict=useStrict==null ?isStrictFast :useStrict; |
738 | | - |
739 | | -if(data.noCharByIndex==null){ |
740 | | -data.noCharByIndex=noCharByIndex; |
741 | | -} |
| 734 | + |
742 | 735 | if(firstArg!='collection'||!data.arrayBranch.inLoop){ |
743 | 736 | data.arrayBranch=null; |
744 | 737 | } |
745 | 738 | // create the function factory |
746 | 739 | varfactory=Function( |
747 | 740 | 'arrayLikeClasses, ArrayProto, bind, compareAscending, concat, createCallback, '+ |
748 | | -'forIn, hasOwnProperty,identity,indexOf, isArguments, isArray, isFunction, '+ |
| 741 | +'forIn, hasOwnProperty, indexOf, isArguments, isArray, isFunction, '+ |
749 | 742 | 'isPlainObject, objectClass, objectTypes, nativeKeys, propertyIsEnumerable, '+ |
750 | 743 | 'slice, stringClass, toString, undefined', |
751 | 744 | 'var callee = function('+args+') {\n'+iteratorTemplate(data)+'\n};\n'+ |
|
754 | 747 | // return the compiled function |
755 | 748 | returnfactory( |
756 | 749 | arrayLikeClasses,ArrayProto,bind,compareAscending,concat,createCallback, |
757 | | -forIn,hasOwnProperty,identity,indexOf,isArguments,isArray,isFunction, |
| 750 | +forIn,hasOwnProperty,indexOf,isArguments,isArray,isFunction, |
758 | 751 | isPlainObject,objectClass,objectTypes,nativeKeys,propertyIsEnumerable, |
759 | 752 | slice,stringClass,toString |
760 | 753 | ); |
|
846 | 839 | // fallback for browsers that can't detect `arguments` objects by [[Class]] |
847 | 840 | if(noArgsClass){ |
848 | 841 | isArguments=function(value){ |
849 | | -return!!(value&&hasOwnProperty.call(value,'callee')); |
| 842 | +returnvalue?hasOwnProperty.call(value,'callee') :false; |
850 | 843 | }; |
851 | 844 | } |
852 | 845 |
|
|
1996 | 1989 | * // => 2 |
1997 | 1990 | */ |
1998 | 1991 | varfind=createIterator(baseIteratorOptions,forEachIteratorOptions,{ |
1999 | | -'init':'', |
| 1992 | +'init':false, |
2000 | 1993 | 'inLoop':'if (callback(value, index, collection)) return value' |
2001 | 1994 | }); |
2002 | 1995 |
|
|
3194 | 3187 | ' return result\n'+ |
3195 | 3188 | '}', |
3196 | 3189 | 'inLoop': |
3197 | | -'if (isFunction(result[index])) {\n'+ |
3198 | | -' result[index] = bind(result[index], result)\n'+ |
| 3190 | +'if (isFunction(value)) {\n'+ |
| 3191 | +' result[index] = bind(value, result)\n'+ |
3199 | 3192 | '}' |
3200 | 3193 | }); |
3201 | 3194 |
|
|