Skip to content

Commit

Permalink
[Robustness] cache Object#isPrototypeOf
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 15, 2015
1 parent 778f77f commit a22c35f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ var isString = require('is-string');
var isSymbol = require('is-symbol');
var isCallable = require('is-callable');

var isProto = Object.prototype.isPrototypeOf;

var foo = function foo() {};
var functionsHaveNames = foo.name === 'foo';

Expand Down Expand Up @@ -162,7 +164,7 @@ module.exports = function isEqual(value, other) {

if (typeof value === 'object' || typeof other === 'object') {
if (typeof value !== typeof other) { return false; }
if (value.isPrototypeOf(other) || other.isPrototypeOf(value)) { return false; }
if (isProto.call(value, other) || isProto.call(other, value)) { return false; }
if (getPrototypeOf(value) !== getPrototypeOf(other)) { return false; }

if (symbolIterator) {
Expand Down

0 comments on commit a22c35f

Please sign in to comment.