Retrieve all the names of the object's properties.

返回对象的所有的属性名称

1 _.keys({one : 1, two : 2, three : 3});
2 => ["one", "two", "three"]

源码:

1   _.keys = nativeKeys || function(obj) {
2     if (obj !== Object(obj)) throw new TypeError('Invalid object');
3     var keys = [];
4     for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key;
5     return keys;
6   };

 

 

 

 

posted on 2012-04-16 21:26  himanhimao  阅读(251)  评论(0编辑  收藏  举报