Skip to content
Browse files

Object methods now use the generic hasOwnProperty to normalize behavi…

…or between IE and others (In IE some objects don't have the hasOwnProperty method).
  • Loading branch information...
1 parent 302afdb commit f9f80871cd0227163ae0db10fc5d77005e8b1142 @cpojer cpojer committed Feb 23, 2011
Showing with 13 additions and 8 deletions.
  1. +2 −1 Source/Core/Core.js
  2. +10 −6 Source/Types/Object.js
  3. +1 −1 Specs
View
3 Source/Core/Core.js
@@ -295,9 +295,10 @@ Number.extend('random', function(min, max){
// forEach, each
+var hasOwnProperty = Object.prototype.hasOwnProperty;
Object.extend('forEach', function(object, fn, bind){
for (var key in object){
- if (object.hasOwnProperty(key)) fn.call(bind, object[key], key, object);
+ if (hasOwnProperty.call(object, key)) fn.call(bind, object[key], key, object);
}
});
View
16 Source/Types/Object.js
@@ -14,6 +14,9 @@ provides: [Object, Hash]
...
*/
+(function(){
+
+var hasOwnProperty = Object.prototype.hasOwnProperty;
Object.extend({
@@ -29,7 +32,7 @@ Object.extend({
map: function(object, fn, bind){
var results = {};
for (var key in object){
- if (object.hasOwnProperty(key)) results[key] = fn.call(bind, object[key], key, object);
+ if (hasOwnProperty.call(object, key)) results[key] = fn.call(bind, object[key], key, object);
}
return results;
},
@@ -44,30 +47,30 @@ Object.extend({
every: function(object, fn, bind){
for (var key in object){
- if (object.hasOwnProperty(key) && !fn.call(bind, object[key], key)) return false;
+ if (hasOwnProperty.call(object, key) && !fn.call(bind, object[key], key)) return false;
}
return true;
},
some: function(object, fn, bind){
for (var key in object){
- if (object.hasOwnProperty(key) && fn.call(bind, object[key], key)) return true;
+ if (hasOwnProperty.call(object, key) && fn.call(bind, object[key], key)) return true;
}
return false;
},
keys: function(object){
var keys = [];
for (var key in object){
- if (object.hasOwnProperty(key)) keys.push(key);
+ if (hasOwnProperty.call(object, key)) keys.push(key);
}
return keys;
},
values: function(object){
var values = [];
for (var key in object){
- if (object.hasOwnProperty(key)) values.push(object[key]);
+ if (hasOwnProperty.call(object, key)) values.push(object[key]);
}
return values;
},
@@ -78,7 +81,7 @@ Object.extend({
keyOf: function(object, value){
for (var key in object){
- if (object.hasOwnProperty(key) && object[key] === value) return key;
+ if (hasOwnProperty.call(object, key) && object[key] === value) return key;
}
return null;
},
@@ -112,6 +115,7 @@ Object.extend({
});
+})();
//<1.2compat>
2 Specs
@@ -1 +1 @@
-Subproject commit 05152e83c2237499c1bf8a80d86b1bba5bb3a631
+Subproject commit 9057280dec39bc7c56b545621dd95b02fea4fc53

0 comments on commit f9f8087

Please sign in to comment.
Something went wrong with that request. Please try again.