Fix object coercion.

This commit is contained in:
John-David Dalton
2017-04-16 15:30:42 -05:00
parent e2941dda3b
commit aa5e1b2fe0
7 changed files with 20 additions and 10 deletions

View File

@@ -11,11 +11,12 @@ const hasOwnProperty = Object.prototype.hasOwnProperty
* @returns {Array} Returns the array of property names.
*/
function baseKeys(object) {
object = Object(object)
if (!isPrototype(object)) {
return Object.keys(Object(object))
return Object.keys(object)
}
const result = []
for (const key in Object(object)) {
for (const key in object) {
if (hasOwnProperty.call(object, key) && key != 'constructor') {
result.push(key)
}

View File

@@ -20,7 +20,9 @@
* // => false
*/
function everyValue(object, predicate) {
const props = Object.keys(Object(object))
object = Object(object)
const props = Object.keys(object)
for (const key of props) {
if (!predicate(object[key], key, object)) {
return false

View File

@@ -17,8 +17,10 @@
* // => [5, 10]
*/
function filterObject(object, predicate) {
object = Object(object)
const result = []
Object.keys(Object(object)).forEach((key) => {
Object.keys(object).forEach((key) => {
const value = object[key]
if (predicate(value, key, object)) {
result.push(value)

View File

@@ -24,9 +24,8 @@
* // => Logs 'a' then 'b' (iteration order is not guaranteed).
*/
function forOwn(object, iteratee) {
if (object != null) {
Object.keys(Object(object)).forEach((key) => iteratee(object[key], key, object))
}
object = Object(object)
Object.keys(object).forEach((key) => iteratee(object[key], key, object))
}
export default forOwn

View File

@@ -18,8 +18,10 @@
* // => { 'a1': 1, 'b2': 2 }
*/
function mapKey(object, iteratee) {
object = Object(object)
const result = {}
Object.keys(Object(object)).forEach((key) => {
Object.keys(object).forEach((key) => {
const value = object[key]
result[iteratee(value, key, object)] = value
})

View File

@@ -21,8 +21,10 @@
* // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
*/
function mapValue(object, iteratee) {
object = Object(object)
const result = {}
Object.keys(Object(object)).forEach((key) => {
Object.keys(object).forEach((key) => {
result[key] = iteratee(object[key], key, object)
})
return result

View File

@@ -15,7 +15,9 @@
* // => true
*/
function someValues(object, predicate) {
const props = Object.keys(Object(object))
object = Object(object)
const props = Object.keys(object)
for (const key of props) {
if (predicate(object[key], key, object)) {
return true