|
798 | 798 |
|
799 | 799 |
|
800 | 800 | $ensureType(factory, FUNCTION); |
801 | | - $define(this, "next", { |
802 | 801 |
|
803 | | - /** |
804 | | - * Advances the enumerator to the next element of the collection. |
805 | | - * @returns {Boolean} |
806 | | - */ |
807 | | - value: function () { |
808 | | - _current = undefined; // reset "current" |
809 | | - _next = false; // reset "next" |
810 | 802 |
|
811 | | - factory(_yielder); |
812 | | - this.current = _current; |
| 803 | + /** |
| 804 | + * Advances the enumerator to the next element of the collection. |
| 805 | + * @returns {Boolean} |
| 806 | + */ |
813 | 807 |
|
814 | | - return _next; |
815 | | - } |
816 | | - }); |
| 808 | + this.next = function () { |
| 809 | + _current = undefined; // reset "current" |
| 810 | + _next = false; // reset "next" |
| 811 | + |
| 812 | + factory(_yielder); |
| 813 | + this.current = _current; |
| 814 | + |
| 815 | + return _next; |
| 816 | + }; |
817 | 817 |
|
818 | 818 |
|
819 | 819 | /** |
|
856 | 856 | obj = obj || []; |
857 | 857 |
|
858 | 858 |
|
859 | | - /// Enumerable object |
860 | | - if ($is(obj, __Enumerable)) { |
861 | | - return obj.getEnumerator(); |
862 | | - } |
863 | | - |
864 | | - |
865 | 859 |
|
866 | 860 | /// ES6/Legacy generator function |
867 | 861 | if ($isFunc(obj)) { |
|
884 | 878 |
|
885 | 879 |
|
886 | 880 |
|
| 881 | + /// Enumerator object |
| 882 | + if ($isFunc(obj.getEnumerator)) { |
| 883 | + return obj.getEnumerator(); |
| 884 | + } |
| 885 | + |
| 886 | + |
| 887 | + |
887 | 888 | /// ES6 Iterable object: Map, Set and Iterable objects |
888 | 889 | if ($isFunc(obj[_iteratorSymbol])) { |
889 | 890 | var _iterator = obj[_iteratorSymbol](), |
|
898 | 899 |
|
899 | 900 |
|
900 | 901 |
|
901 | | - /// Enumerator object |
902 | | - if ($isFunc(obj.getEnumerator)) { |
903 | | - return obj.getEnumerator(); |
904 | | - } |
905 | | - |
906 | | - |
907 | | - |
908 | 902 | /// Regular object |
909 | 903 | return function () { |
910 | 904 |
|
|
1056 | 1050 |
|
1057 | 1051 |
|
1058 | 1052 | function Comparer(comparison) { |
1059 | | - $ensureType(comparison, FUNCTION); |
1060 | | - $define(this, "_comparison", { value: comparison }); |
| 1053 | + if ($isFunc(comparison)) { |
| 1054 | + $define(this, "compare", { value: comparison }); |
| 1055 | + } |
1061 | 1056 | } |
1062 | 1057 |
|
1063 | 1058 | return $extend(Comparer, |
|
1072 | 1067 | * Greater than zero x is greater than y. |
1073 | 1068 | */ |
1074 | 1069 | compare: function (objA, objB) { |
1075 | | - return this._comparison(objA, objB); |
| 1070 | + return $computeCompare(objA, objB); |
1076 | 1071 | } |
1077 | 1072 | }, |
1078 | 1073 | { |
1079 | 1074 |
|
1080 | 1075 | /** |
1081 | 1076 | * Gets a default sort order comparer for the type specified by the generic argument. |
1082 | 1077 | */ |
1083 | | - defaultComparer: new Comparer($computeCompare), |
| 1078 | + defaultComparer: new Comparer(), |
1084 | 1079 |
|
1085 | 1080 |
|
1086 | 1081 | /** |
|
1102 | 1097 |
|
1103 | 1098 | function EqualityComparer(hashCodeProvider, equality) { |
1104 | 1099 |
|
1105 | | - $ensureType(equality, FUNCTION); |
1106 | | - $ensureType(hashCodeProvider, FUNCTION); |
| 1100 | + if ($isFunc(equality)) { |
| 1101 | + $define(this, "equals", { value: equality }); |
| 1102 | + } |
1107 | 1103 |
|
1108 | | - $define(this, "_equality", { value: equality }); |
1109 | | - $define(this, "_hashCodeProvider", { value: hashCodeProvider }); |
| 1104 | + if ($isFunc(hashCodeProvider)) { |
| 1105 | + $define(this, "hash", { value: hashCodeProvider }); |
| 1106 | + } |
1110 | 1107 | } |
1111 | 1108 |
|
1112 | 1109 |
|
|
1119 | 1116 | * @returns true if the specified objects are equal; otherwise, false. |
1120 | 1117 | */ |
1121 | 1118 | equals: function (x, y) { |
1122 | | - return this._equality(x, y); |
| 1119 | + return $computeEquals(x, y, true); |
1123 | 1120 | }, |
1124 | 1121 |
|
1125 | 1122 | /** |
|
1128 | 1125 | * @returns A hash code for the specified object. |
1129 | 1126 | */ |
1130 | 1127 | hash: function (obj) { |
1131 | | - return this._hashCodeProvider(obj); |
| 1128 | + return $computeHash(obj, true); |
1132 | 1129 | } |
1133 | 1130 | }, |
1134 | 1131 | { |
1135 | 1132 |
|
1136 | 1133 | /** |
1137 | 1134 | * Gets a default equality comparer for the type specified by the generic argument. |
1138 | 1135 | */ |
1139 | | - defaultComparer: new EqualityComparer($hash, $equals), |
| 1136 | + defaultComparer: new EqualityComparer(), |
1140 | 1137 |
|
1141 | 1138 | /** |
1142 | 1139 | * Creates an EqualityComparer by using the specified equality and hashCodeProvider. |
|
1177 | 1174 |
|
1178 | 1175 | var _source = $prop(this); |
1179 | 1176 |
|
1180 | | - if(_source){ |
| 1177 | + if (_source) { |
1181 | 1178 | return $count(_source); |
1182 | 1179 | } |
1183 | 1180 |
|
|
0 commit comments