Cleanup iteratorTemplate and isPlainObject.

Former-commit-id: a96b8716cfd0efbc46daf2307fae8f1ee5969862
This commit is contained in:
John-David Dalton
2012-09-03 15:36:18 -07:00
parent 08300183b3
commit 5477d3c292

View File

@@ -447,8 +447,8 @@
// else using a for-in loop // else using a for-in loop
' <% } else { %>\n' + ' <% } else { %>\n' +
' <%= objectBranch.beforeLoop %>;\n' + ' <%= objectBranch.beforeLoop %>;\n' +
' for (index in iteratee) {' + ' for (index in iteratee) {<%' +
' <% if (!hasDontEnumBug || useHas) { %>\n if (<%' + ' if (!hasDontEnumBug || useHas) { %>\n if (<%' +
' if (!hasDontEnumBug) { %>!(skipProto && index == \'prototype\')<% }' + ' if (!hasDontEnumBug) { %>!(skipProto && index == \'prototype\')<% }' +
' if (!hasDontEnumBug && useHas) { %> && <% }' + ' if (!hasDontEnumBug && useHas) { %> && <% }' +
' if (useHas) { %>hasOwnProperty.call(iteratee, index)<% }' + ' if (useHas) { %>hasOwnProperty.call(iteratee, index)<% }' +
@@ -966,14 +966,16 @@
} }
/** /**
* A fallback implementation of `isPlainObject`. * A fallback implementation of `isPlainObject` that checks if a given `value`
* is an object created by the `Object` constructor, assuming objects created
* by the `Object` constructor have no inherited enumerable properties and that
* there are no `Object.prototype` extensions.
* *
* @private * @private
* @param {Mixed} value The value to check. * @param {Mixed} value The value to check.
* @param {Boolean} [skipArgsCheck=false] Internally used to skip checks for * @param {Boolean} [skipArgsCheck=false] Internally used to skip checks for
* `arguments` objects. * `arguments` objects.
* @returns {Boolean} Returns `true` if the `value` is a plain `Object` object, * @returns {Boolean} Returns `true` if `value` is a plain object, else `false`.
* else `false`.
*/ */
function isPlainFallback(value, skipArgsCheck) { function isPlainFallback(value, skipArgsCheck) {
// avoid non-objects and false positives for `arguments` objects // avoid non-objects and false positives for `arguments` objects
@@ -1009,23 +1011,20 @@
} }
/** /**
* Checks if a given `value` is an object created by the `Object` constructor * Checks if a given `value` is an object created by the `Object` constructor.
* assuming objects created by the `Object` constructor have no inherited
* enumerable properties and that there are no `Object.prototype` extensions.
* *
* @private * @private
* @param {Mixed} value The value to check. * @param {Mixed} value The value to check.
* @param {Boolean} [skipArgsCheck=false] Internally used to skip checks for * @param {Boolean} [skipArgsCheck=false] Internally used to skip checks for
* `arguments` objects. * `arguments` objects.
* @returns {Boolean} Returns `true` if the `value` is a plain `Object` object, * @returns {Boolean} Returns `true` if `value` is a plain object, else `false`.
* else `false`.
*/ */
var isPlainObject = objectTypes.__proto__ != ObjectProto ? isPlainFallback : function(value, skipArgsCheck) { var isPlainObject = objectTypes.__proto__ != ObjectProto ? isPlainFallback : function(value, skipArgsCheck) {
if (!value) { if (!value) {
return false; return false;
} }
var valueOf = value.valueOf, var valueOf = value.valueOf,
objProto = typeof valueOf == 'function' && valueOf.__proto__.__proto__; objProto = typeof valueOf == 'function' && (objProto = valueOf.__proto__) && objProto.__proto__;
return objProto return objProto
? value == objProto || (value.__proto__ == objProto && (skipArgsCheck || !isArguments(value))) ? value == objProto || (value.__proto__ == objProto && (skipArgsCheck || !isArguments(value)))