Skip to content

Commit

Permalink
better compatability fallbacks for ff, maybe ie
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Sep 11, 2010
1 parent b9750ff commit 33577aa
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 31 deletions.
59 changes: 29 additions & 30 deletions lib/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function Hash (hash, xs) {
Object.keys(hash).forEach(function (key) {
f.call(self, hash[key], key);
});
memoized = {};
return self;
},
filter : function (f) {
Expand Down Expand Up @@ -55,7 +54,6 @@ function Hash (hash, xs) {
Object.keys(h).forEach(function (key) {
hash[key] = h[key];
});
memoized = {};
return self;
},
merge : function (h) {
Expand All @@ -74,7 +72,6 @@ function Hash (hash, xs) {
},
tap : function (f) {
f.call(self, hash);
memoized = {};
return self;
},
extract : function (keys) {
Expand All @@ -88,34 +85,36 @@ function Hash (hash, xs) {
items : hash
};

Object.defineProperty(self, 'keys', { get : function () {
return Object.keys(hash);
} });

Object.defineProperty(self, 'values', { get : function () {
return Object.keys(hash)
.map(function (key) { return hash[key] });
} });

Object.defineProperty(self, 'compact', { get : function () {
return self.filter(function (x) { return x !== undefined });
} });

Object.defineProperty(self, 'clone', { get : function () {
return Hash(Hash.clone(hash));
} });

Object.defineProperty(self, 'copy', { get : function () {
return Hash(Hash.copy(hash));
} });

Object.defineProperty(self, 'length', { get : function () {
return Object.keys(hash).length;
} });
var props = {
keys : function () { return Object.keys(hash) },
values : function () {
return Object.keys(hash).map(function (key) { return hash[key] });
},
compact : function () {
return self.filter(function (x) { return x !== undefined });
},
clone : function () { return Hash(Hash.clone(hash)) },
copy : function () { return Hash(Hash.copy(hash)) },
length : function () { return Object.keys(hash).length },
size : function () { return self.length }
};

Object.defineProperty(self, 'size', { get : function () {
return self.length;
} });
if (self.__defineGetter__) {
for (var key in props) {
self.__defineGetter__(key, props[key]);
}
}
else if (Object.defineProperty) {
for (var key in props) {
Object.defineProperty(self, key, { get : props[key] });
}
}
else {
// non-lazy version for browsers that suck >_<
for (var key in props) {
self[key] = prop();
}
}

return self;
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "traverse",
"version" : "0.2.0",
"version" : "0.2.1",
"description" : "Traverse and transform objects by visiting every node on a recursive walk.",
"author" : "James Halliday",
"license" : "MIT/X11",
Expand Down

0 comments on commit 33577aa

Please sign in to comment.