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

Open
wants to merge 2 commits into
from

Conversation

Projects
None yet
2 participants
@crcn

crcn commented Oct 30, 2012

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"]
@tmcw

This comment has been minimized.

Show comment Hide comment
@tmcw

tmcw Apr 13, 2014

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

tmcw commented Apr 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