Skip to content

Commit

Permalink
Adding a getPrototypeOf shim
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 14, 2014
1 parent dd86cc1 commit 3c59ef9
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@
var toString = Object.prototype.toString;
var has = Object.prototype.hasOwnProperty;

var getPrototypeOf = Object.getPrototypeOf;
if (!getPrototypeOf) {
if (typeof this.__proto__ === "object") {
getPrototypeOf = function (obj) {
return obj.__proto__;
};
} else {
getPrototypeOf = function (obj) {
var constructor = obj.constructor,
oldConstructor;
if (has.call(obj, 'constructor')) {
oldConstructor = constructor;
if (!(delete obj.constructor)) { // reset constructor
return null; // can't delete obj.constructor, return null
}
constructor = obj.constructor; // get real constructor
obj.constructor = oldConstructor; // restore constructor
}
return constructor ? constructor.prototype : null; // needed for IE
};
}
}

var dateType = '[object Date]';
var regexType = '[object RegExp]';
var arrayType = '[object Array]';
Expand Down Expand Up @@ -34,7 +57,7 @@ module.exports = function isEqual(value, other) {
}

if (type === objType) {
if (Object.getPrototypeOf(value) !== Object.getPrototypeOf(other)) { return false; }
if (getPrototypeOf(value) !== getPrototypeOf(other)) { return false; }
var key;
for (key in value) {
if (has.call(value, key)) {
Expand Down

0 comments on commit 3c59ef9

Please sign in to comment.