Skip to content

Commit

Permalink
fix for ie<9, doesn't have hasOwnProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Jul 26, 2013
1 parent 5ed0d88 commit 6b7d611
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
else if (typeof obj === 'object' && !isDate(obj) && !isRegExp(obj)) {
var xs = [];
for (var key in obj) {
if ({}.hasOwnProperty.call(obj, key)) {
if (/[^\w$]/.test(key)) {
xs.push(inspect(key) + ': ' + inspect(obj[key], obj));
}
else xs.push(key + ': ' + inspect(obj[key], obj));
if (!has(obj, key)) continue;
if (/[^\w$]/.test(key)) {
xs.push(inspect(key) + ': ' + inspect(obj[key], obj));
}
else xs.push(key + ': ' + inspect(obj[key], obj));
}
return '{ ' + xs.join(', ') + ' }';
}
Expand All @@ -72,3 +71,8 @@ function isDate (obj) {
function isRegExp (obj) {
return {}.toString.call(obj) === '[object RegExp]';
}

function has (obj, key) {
if (!{}.hasOwnProperty) return true;
return {}.hasOwnProperty.call(obj, key);
}

0 comments on commit 6b7d611

Please sign in to comment.