Skip to content

Commit

Permalink
Using Object.keys() instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
hemanth committed Jun 2, 2014
1 parent 357be95 commit ebdf41d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
12 changes: 2 additions & 10 deletions es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -762,15 +762,7 @@
},

getPropertyNames: function(subject) {
var getOwnPropertyNames = function(object){
var props = [];
for (var key in object) {
if (object.hasOwnProperty(key))
props.push(key);
}
return props;
};
var result = getOwnPropertyNames(subject);
var result = Object.keys(subject);
var proto = Object.getPrototypeOf(subject);

var addProperty = function(property) {
Expand All @@ -780,7 +772,7 @@
};

while (proto !== null) {
getOwnPropertyNames(proto).forEach(addProperty);
Object.keys(proto).forEach(addProperty);
proto = Object.getPrototypeOf(proto);
}
return result;
Expand Down
12 changes: 2 additions & 10 deletions test/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,13 @@ describe('Object', function() {
});

describe('Object.getPropertyNames()', function() {
var getOwnPropertyNames = function(object){
var props = [];
for (var key in object) {
if (object.hasOwnProperty(key))
props.push(key);
}
return props;
};
it('should produce an array of property names including inherited ones',
function() {
expect(Object.getPropertyNames(Object.create(null))).to.eql([]);
var obj = {};
expect(Object.getPropertyNames(Object.create(obj))).to.eql(
getOwnPropertyNames(obj).concat(
getOwnPropertyNames(Object.getPrototypeOf(obj))
Object.keys(obj).concat(
Object.keys(Object.getPrototypeOf(obj))
)
);
});
Expand Down

0 comments on commit ebdf41d

Please sign in to comment.