Skip to content
This repository

replace Object.keys(target) w/ for(var key in target) { } #27

wants to merge 2 commits into from

2 participants

Craig Condon Tom MacWright
Craig Condon

Both functions behave differently. Take this for example:

var Post = function(title, message) {
    this.title = title;
    this.message = message;

Post.prototype.collection = "posts";

Post.prototype.findOne = function() {
    //do stuff

Post.prototype.find = function() {
    //do more stuff

function objectKeys(target) {
    var keys = [];
    for(var k in target) keys.push(k);
    return keys;

var post = new Post("test", "message");
console.log(Object.keys(post)); //["title", "message"]
console.log(objectKeys(post)); //["title", "message", "collection", "findOne", "find"]
Tom MacWright
tmcw commented April 13, 2014

I'd rather this module not look up the prototype chain like this - Object.keys seems like the appropriate way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 2 authors.

Oct 29, 2012
Craig Condon remove Object.keys(key) since it behaves differently than for(var key…
… in target)...
Nov 01, 2012
add deps cfd8dba
Something went wrong with that request. Please try again.