From 447fbd991c81793754277aa15d009d25c4b2ac2b Mon Sep 17 00:00:00 2001 From: "Frank.Qiu" Date: Fri, 2 Mar 2018 17:46:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0union,zipObject?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/bundle.js | 82 ++++++++++++++++++++++++++++++++++++---------- dist/core.js | 82 ++++++++++++++++++++++++++++++++++++---------- dist/fineui.js | 82 ++++++++++++++++++++++++++++++++++++---------- lodash.md | 2 +- src/core/lodash.js | 82 ++++++++++++++++++++++++++++++++++++---------- utils/utils.js | 82 ++++++++++++++++++++++++++++++++++++---------- 6 files changed, 326 insertions(+), 86 deletions(-) diff --git a/dist/bundle.js b/dist/bundle.js index c025ad8e9f..4e359dadad 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -9599,7 +9599,7 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { })( window );/** * @license * Lodash (Custom Build) - * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy"` + * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy,union,zipObject"` * Copyright JS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 @@ -12774,6 +12774,28 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { }, result); } + /** + * This base implementation of `_.zipObject` which assigns values using `assignFunc`. + * + * @private + * @param {Array} props The property identifiers. + * @param {Array} values The property values. + * @param {Function} assignFunc The function to assign values. + * @returns {Object} Returns the new object. + */ + function baseZipObject(props, values, assignFunc) { + var index = -1, + length = props.length, + valsLength = values.length, + result = {}; + + while (++index < length) { + var value = index < valsLength ? values[index] : undefined; + assignFunc(result, props[index], value); + } + return result; + } + /** * Casts `value` to an empty array if it's not an array like object. * @@ -15150,6 +15172,26 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return baseSlice(array, start, end); } + /** + * Creates an array of unique values, in order, from all given arrays using + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @returns {Array} Returns the new array of combined values. + * @example + * + * _.union([2], [1, 2]); + * // => [2, 1] + */ + var union = baseRest(function(arrays) { + return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true)); + }); + /** * Creates a duplicate-free version of an array, using * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) @@ -15252,6 +15294,26 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { */ var zip = baseRest(unzip); + /** + * This method is like `_.fromPairs` except that it accepts two arrays, + * one of property identifiers and one of corresponding values. + * + * @static + * @memberOf _ + * @since 0.4.0 + * @category Array + * @param {Array} [props=[]] The property identifiers. + * @param {Array} [values=[]] The property values. + * @returns {Object} Returns the new object. + * @example + * + * _.zipObject(['a', 'b'], [1, 2]); + * // => { 'a': 1, 'b': 2 } + */ + function zipObject(props, values) { + return baseZipObject(props || [], values || [], assignValue); + } + /*------------------------------------------------------------------------*/ /** @@ -18198,21 +18260,6 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return baseRandom(lower, upper); } - // Converts lists into objects. Pass either a single array of `[key, value]` - // pairs, or two parallel arrays of the same length -- one of keys, and one of - // the corresponding values. - function object (list, values) { - var result = {}; - for (var i = 0, length = list && list.length; i < length; i++) { - if (values) { - result[list[i]] = values[i]; - } else { - result[list[i][0]] = list[i][1]; - } - } - return result; - } - /*------------------------------------------------------------------------*/ /** @@ -18704,11 +18751,13 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { lodash.throttle = throttle; lodash.thru = thru; lodash.toArray = toArray; + lodash.union = union; lodash.uniq = uniq; lodash.uniqBy = uniqBy; lodash.unzip = unzip; lodash.values = values; lodash.zip = zip; + lodash.zipObject = zipObject; // Add aliases. lodash.extend = assignIn; @@ -18760,7 +18809,6 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { lodash.size = size; lodash.some = some; lodash.uniqueId = uniqueId; - lodash.object = object; // Add aliases. lodash.each = forEach; diff --git a/dist/core.js b/dist/core.js index ae0ca4c646..59f75679e4 100644 --- a/dist/core.js +++ b/dist/core.js @@ -9599,7 +9599,7 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { })( window );/** * @license * Lodash (Custom Build) - * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy"` + * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy,union,zipObject"` * Copyright JS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 @@ -12774,6 +12774,28 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { }, result); } + /** + * This base implementation of `_.zipObject` which assigns values using `assignFunc`. + * + * @private + * @param {Array} props The property identifiers. + * @param {Array} values The property values. + * @param {Function} assignFunc The function to assign values. + * @returns {Object} Returns the new object. + */ + function baseZipObject(props, values, assignFunc) { + var index = -1, + length = props.length, + valsLength = values.length, + result = {}; + + while (++index < length) { + var value = index < valsLength ? values[index] : undefined; + assignFunc(result, props[index], value); + } + return result; + } + /** * Casts `value` to an empty array if it's not an array like object. * @@ -15150,6 +15172,26 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return baseSlice(array, start, end); } + /** + * Creates an array of unique values, in order, from all given arrays using + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @returns {Array} Returns the new array of combined values. + * @example + * + * _.union([2], [1, 2]); + * // => [2, 1] + */ + var union = baseRest(function(arrays) { + return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true)); + }); + /** * Creates a duplicate-free version of an array, using * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) @@ -15252,6 +15294,26 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { */ var zip = baseRest(unzip); + /** + * This method is like `_.fromPairs` except that it accepts two arrays, + * one of property identifiers and one of corresponding values. + * + * @static + * @memberOf _ + * @since 0.4.0 + * @category Array + * @param {Array} [props=[]] The property identifiers. + * @param {Array} [values=[]] The property values. + * @returns {Object} Returns the new object. + * @example + * + * _.zipObject(['a', 'b'], [1, 2]); + * // => { 'a': 1, 'b': 2 } + */ + function zipObject(props, values) { + return baseZipObject(props || [], values || [], assignValue); + } + /*------------------------------------------------------------------------*/ /** @@ -18198,21 +18260,6 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return baseRandom(lower, upper); } - // Converts lists into objects. Pass either a single array of `[key, value]` - // pairs, or two parallel arrays of the same length -- one of keys, and one of - // the corresponding values. - function object (list, values) { - var result = {}; - for (var i = 0, length = list && list.length; i < length; i++) { - if (values) { - result[list[i]] = values[i]; - } else { - result[list[i][0]] = list[i][1]; - } - } - return result; - } - /*------------------------------------------------------------------------*/ /** @@ -18704,11 +18751,13 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { lodash.throttle = throttle; lodash.thru = thru; lodash.toArray = toArray; + lodash.union = union; lodash.uniq = uniq; lodash.uniqBy = uniqBy; lodash.unzip = unzip; lodash.values = values; lodash.zip = zip; + lodash.zipObject = zipObject; // Add aliases. lodash.extend = assignIn; @@ -18760,7 +18809,6 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { lodash.size = size; lodash.some = some; lodash.uniqueId = uniqueId; - lodash.object = object; // Add aliases. lodash.each = forEach; diff --git a/dist/fineui.js b/dist/fineui.js index 61687f2541..95b456d4a3 100644 --- a/dist/fineui.js +++ b/dist/fineui.js @@ -9800,7 +9800,7 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { })( window );/** * @license * Lodash (Custom Build) - * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy"` + * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy,union,zipObject"` * Copyright JS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 @@ -12975,6 +12975,28 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { }, result); } + /** + * This base implementation of `_.zipObject` which assigns values using `assignFunc`. + * + * @private + * @param {Array} props The property identifiers. + * @param {Array} values The property values. + * @param {Function} assignFunc The function to assign values. + * @returns {Object} Returns the new object. + */ + function baseZipObject(props, values, assignFunc) { + var index = -1, + length = props.length, + valsLength = values.length, + result = {}; + + while (++index < length) { + var value = index < valsLength ? values[index] : undefined; + assignFunc(result, props[index], value); + } + return result; + } + /** * Casts `value` to an empty array if it's not an array like object. * @@ -15351,6 +15373,26 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return baseSlice(array, start, end); } + /** + * Creates an array of unique values, in order, from all given arrays using + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @returns {Array} Returns the new array of combined values. + * @example + * + * _.union([2], [1, 2]); + * // => [2, 1] + */ + var union = baseRest(function(arrays) { + return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true)); + }); + /** * Creates a duplicate-free version of an array, using * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) @@ -15453,6 +15495,26 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { */ var zip = baseRest(unzip); + /** + * This method is like `_.fromPairs` except that it accepts two arrays, + * one of property identifiers and one of corresponding values. + * + * @static + * @memberOf _ + * @since 0.4.0 + * @category Array + * @param {Array} [props=[]] The property identifiers. + * @param {Array} [values=[]] The property values. + * @returns {Object} Returns the new object. + * @example + * + * _.zipObject(['a', 'b'], [1, 2]); + * // => { 'a': 1, 'b': 2 } + */ + function zipObject(props, values) { + return baseZipObject(props || [], values || [], assignValue); + } + /*------------------------------------------------------------------------*/ /** @@ -18399,21 +18461,6 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return baseRandom(lower, upper); } - // Converts lists into objects. Pass either a single array of `[key, value]` - // pairs, or two parallel arrays of the same length -- one of keys, and one of - // the corresponding values. - function object (list, values) { - var result = {}; - for (var i = 0, length = list && list.length; i < length; i++) { - if (values) { - result[list[i]] = values[i]; - } else { - result[list[i][0]] = list[i][1]; - } - } - return result; - } - /*------------------------------------------------------------------------*/ /** @@ -18905,11 +18952,13 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { lodash.throttle = throttle; lodash.thru = thru; lodash.toArray = toArray; + lodash.union = union; lodash.uniq = uniq; lodash.uniqBy = uniqBy; lodash.unzip = unzip; lodash.values = values; lodash.zip = zip; + lodash.zipObject = zipObject; // Add aliases. lodash.extend = assignIn; @@ -18961,7 +19010,6 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { lodash.size = size; lodash.some = some; lodash.uniqueId = uniqueId; - lodash.object = object; // Add aliases. lodash.each = forEach; diff --git a/lodash.md b/lodash.md index 5c7bd22809..aa9d23bb50 100644 --- a/lodash.md +++ b/lodash.md @@ -1 +1 @@ -lodash core plus=debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy,object +lodash core plus=debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy,union,zipObject \ No newline at end of file diff --git a/src/core/lodash.js b/src/core/lodash.js index 5c6c85ccd5..094fbc1c48 100644 --- a/src/core/lodash.js +++ b/src/core/lodash.js @@ -1,7 +1,7 @@ /** * @license * Lodash (Custom Build) - * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy"` + * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy,union,zipObject"` * Copyright JS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 @@ -3176,6 +3176,28 @@ }, result); } + /** + * This base implementation of `_.zipObject` which assigns values using `assignFunc`. + * + * @private + * @param {Array} props The property identifiers. + * @param {Array} values The property values. + * @param {Function} assignFunc The function to assign values. + * @returns {Object} Returns the new object. + */ + function baseZipObject(props, values, assignFunc) { + var index = -1, + length = props.length, + valsLength = values.length, + result = {}; + + while (++index < length) { + var value = index < valsLength ? values[index] : undefined; + assignFunc(result, props[index], value); + } + return result; + } + /** * Casts `value` to an empty array if it's not an array like object. * @@ -5552,6 +5574,26 @@ return baseSlice(array, start, end); } + /** + * Creates an array of unique values, in order, from all given arrays using + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @returns {Array} Returns the new array of combined values. + * @example + * + * _.union([2], [1, 2]); + * // => [2, 1] + */ + var union = baseRest(function(arrays) { + return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true)); + }); + /** * Creates a duplicate-free version of an array, using * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) @@ -5654,6 +5696,26 @@ */ var zip = baseRest(unzip); + /** + * This method is like `_.fromPairs` except that it accepts two arrays, + * one of property identifiers and one of corresponding values. + * + * @static + * @memberOf _ + * @since 0.4.0 + * @category Array + * @param {Array} [props=[]] The property identifiers. + * @param {Array} [values=[]] The property values. + * @returns {Object} Returns the new object. + * @example + * + * _.zipObject(['a', 'b'], [1, 2]); + * // => { 'a': 1, 'b': 2 } + */ + function zipObject(props, values) { + return baseZipObject(props || [], values || [], assignValue); + } + /*------------------------------------------------------------------------*/ /** @@ -8600,21 +8662,6 @@ return baseRandom(lower, upper); } - // Converts lists into objects. Pass either a single array of `[key, value]` - // pairs, or two parallel arrays of the same length -- one of keys, and one of - // the corresponding values. - function object (list, values) { - var result = {}; - for (var i = 0, length = list && list.length; i < length; i++) { - if (values) { - result[list[i]] = values[i]; - } else { - result[list[i][0]] = list[i][1]; - } - } - return result; - } - /*------------------------------------------------------------------------*/ /** @@ -9106,11 +9153,13 @@ lodash.throttle = throttle; lodash.thru = thru; lodash.toArray = toArray; + lodash.union = union; lodash.uniq = uniq; lodash.uniqBy = uniqBy; lodash.unzip = unzip; lodash.values = values; lodash.zip = zip; + lodash.zipObject = zipObject; // Add aliases. lodash.extend = assignIn; @@ -9162,7 +9211,6 @@ lodash.size = size; lodash.some = some; lodash.uniqueId = uniqueId; - lodash.object = object; // Add aliases. lodash.each = forEach; diff --git a/utils/utils.js b/utils/utils.js index c10a4dceb2..2810bd9836 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -1,7 +1,7 @@ /** * @license * Lodash (Custom Build) - * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy"` + * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy,union,zipObject"` * Copyright JS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 @@ -3176,6 +3176,28 @@ }, result); } + /** + * This base implementation of `_.zipObject` which assigns values using `assignFunc`. + * + * @private + * @param {Array} props The property identifiers. + * @param {Array} values The property values. + * @param {Function} assignFunc The function to assign values. + * @returns {Object} Returns the new object. + */ + function baseZipObject(props, values, assignFunc) { + var index = -1, + length = props.length, + valsLength = values.length, + result = {}; + + while (++index < length) { + var value = index < valsLength ? values[index] : undefined; + assignFunc(result, props[index], value); + } + return result; + } + /** * Casts `value` to an empty array if it's not an array like object. * @@ -5552,6 +5574,26 @@ return baseSlice(array, start, end); } + /** + * Creates an array of unique values, in order, from all given arrays using + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @returns {Array} Returns the new array of combined values. + * @example + * + * _.union([2], [1, 2]); + * // => [2, 1] + */ + var union = baseRest(function(arrays) { + return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true)); + }); + /** * Creates a duplicate-free version of an array, using * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) @@ -5654,6 +5696,26 @@ */ var zip = baseRest(unzip); + /** + * This method is like `_.fromPairs` except that it accepts two arrays, + * one of property identifiers and one of corresponding values. + * + * @static + * @memberOf _ + * @since 0.4.0 + * @category Array + * @param {Array} [props=[]] The property identifiers. + * @param {Array} [values=[]] The property values. + * @returns {Object} Returns the new object. + * @example + * + * _.zipObject(['a', 'b'], [1, 2]); + * // => { 'a': 1, 'b': 2 } + */ + function zipObject(props, values) { + return baseZipObject(props || [], values || [], assignValue); + } + /*------------------------------------------------------------------------*/ /** @@ -8600,21 +8662,6 @@ return baseRandom(lower, upper); } - // Converts lists into objects. Pass either a single array of `[key, value]` - // pairs, or two parallel arrays of the same length -- one of keys, and one of - // the corresponding values. - function object (list, values) { - var result = {}; - for (var i = 0, length = list && list.length; i < length; i++) { - if (values) { - result[list[i]] = values[i]; - } else { - result[list[i][0]] = list[i][1]; - } - } - return result; - } - /*------------------------------------------------------------------------*/ /** @@ -9106,11 +9153,13 @@ lodash.throttle = throttle; lodash.thru = thru; lodash.toArray = toArray; + lodash.union = union; lodash.uniq = uniq; lodash.uniqBy = uniqBy; lodash.unzip = unzip; lodash.values = values; lodash.zip = zip; + lodash.zipObject = zipObject; // Add aliases. lodash.extend = assignIn; @@ -9162,7 +9211,6 @@ lodash.size = size; lodash.some = some; lodash.uniqueId = uniqueId; - lodash.object = object; // Add aliases. lodash.each = forEach; From 5d798c28a6db88c0a5e974c1d34bef4f3d2aa670 Mon Sep 17 00:00:00 2001 From: "Frank.Qiu" Date: Mon, 5 Mar 2018 10:34:38 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=9B=AE=E5=89=8D=E5=8F=91=E7=8E=B0?= =?UTF-8?q?=E7=9A=84ie8=E4=B8=8B=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/fineui.js | 44 +++++++++++++++++++++++++++++++++++++++++- dist/polyfill.js | 44 +++++++++++++++++++++++++++++++++++++++++- src/polyfill/lodash.js | 43 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 src/polyfill/lodash.js diff --git a/dist/fineui.js b/dist/fineui.js index 95b456d4a3..c2a468b3dd 100644 --- a/dist/fineui.js +++ b/dist/fineui.js @@ -154,7 +154,49 @@ window.localStorage || (window.localStorage = { clear: function () { this.items = {}; } -});if (typeof Set !== "undefined" && Set.toString().match(/native code/)) { +}); +if (!Object.keys) { + Object.keys = function(o) { + if (o !== Object(o)) { + throw new TypeError('Object.keys called on a non-object'); + } + // fix的问题 + var falsy; + var skipArray = { + __ob__: falsy, + $accessors: falsy, + $vbthis: falsy, + $vbsetter: falsy + }; + var k = [], p; + for (p in o) { + if (!(p in skipArray)) { + if (Object.prototype.hasOwnProperty.call(o, p)) { + k.push(p); + } + } + } + return k; + }; +} + +if (!Array.isArray) { + Array.isArray = function(arg) { + return Object.prototype.toString.call(arg) === '[object Array]'; + }; +} + +// https://stackoverflow.com/questions/10919915/ie8-getprototypeof-method +if (typeof Object.getPrototypeOf !== "function") { + Object.getPrototypeOf = "".__proto__ === String.prototype + ? function (object) { + return object.__proto__; + } + : function (object) { + // May break if the constructor has been tampered with + return object.constructor.prototype; + }; +}if (typeof Set !== "undefined" && Set.toString().match(/native code/)) { } else { Set = function () { diff --git a/dist/polyfill.js b/dist/polyfill.js index 052cfb5741..47f771c9df 100644 --- a/dist/polyfill.js +++ b/dist/polyfill.js @@ -154,7 +154,49 @@ window.localStorage || (window.localStorage = { clear: function () { this.items = {}; } -});if (typeof Set !== "undefined" && Set.toString().match(/native code/)) { +}); +if (!Object.keys) { + Object.keys = function(o) { + if (o !== Object(o)) { + throw new TypeError('Object.keys called on a non-object'); + } + // fix的问题 + var falsy; + var skipArray = { + __ob__: falsy, + $accessors: falsy, + $vbthis: falsy, + $vbsetter: falsy + }; + var k = [], p; + for (p in o) { + if (!(p in skipArray)) { + if (Object.prototype.hasOwnProperty.call(o, p)) { + k.push(p); + } + } + } + return k; + }; +} + +if (!Array.isArray) { + Array.isArray = function(arg) { + return Object.prototype.toString.call(arg) === '[object Array]'; + }; +} + +// https://stackoverflow.com/questions/10919915/ie8-getprototypeof-method +if (typeof Object.getPrototypeOf !== "function") { + Object.getPrototypeOf = "".__proto__ === String.prototype + ? function (object) { + return object.__proto__; + } + : function (object) { + // May break if the constructor has been tampered with + return object.constructor.prototype; + }; +}if (typeof Set !== "undefined" && Set.toString().match(/native code/)) { } else { Set = function () { diff --git a/src/polyfill/lodash.js b/src/polyfill/lodash.js new file mode 100644 index 0000000000..e01c30f80a --- /dev/null +++ b/src/polyfill/lodash.js @@ -0,0 +1,43 @@ + +if (!Object.keys) { + Object.keys = function(o) { + if (o !== Object(o)) { + throw new TypeError('Object.keys called on a non-object'); + } + // fix的问题 + var falsy; + var skipArray = { + __ob__: falsy, + $accessors: falsy, + $vbthis: falsy, + $vbsetter: falsy + }; + var k = [], p; + for (p in o) { + if (!(p in skipArray)) { + if (Object.prototype.hasOwnProperty.call(o, p)) { + k.push(p); + } + } + } + return k; + }; +} + +if (!Array.isArray) { + Array.isArray = function(arg) { + return Object.prototype.toString.call(arg) === '[object Array]'; + }; +} + +// https://stackoverflow.com/questions/10919915/ie8-getprototypeof-method +if (typeof Object.getPrototypeOf !== "function") { + Object.getPrototypeOf = "".__proto__ === String.prototype + ? function (object) { + return object.__proto__; + } + : function (object) { + // May break if the constructor has been tampered with + return object.constructor.prototype; + }; +} \ No newline at end of file