miktam / sizeof

Get size of a JavaScript object
MIT License
311 stars 45 forks source link

Depends on instance attribute `hasOwnProperty` #13

Closed jdthorpe closed 8 years ago

jdthorpe commented 8 years ago

These calls all throw the error TypeError: object.hasOwnProperty is not a function:

sizeof = require('object-sizeof')
sizeof({hasOwnProperty:undefined})
sizeof({hasOwnProperty:"Hello World"})
sizeof({hasOwnProperty:1234})

For greater robustness, I recommend changing this:

if(!object.hasOwnProperty(key)){
    continue;
}

to the more general:

if(!Object.hasOwnProperty.call(object,key)){
    continue;
}
miktam commented 8 years ago

thank you, @jdthorpe fixed https://github.com/miktam/sizeof/pull/14