Skip to content

Commit

Permalink
Use try/catch for a more reliable isFunction check, even with ES6 @@t…
Browse files Browse the repository at this point in the history
…oStringTag
  • Loading branch information
ljharb committed Jan 28, 2015
1 parent 612bf6b commit c7c47c1
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var ObjectPrototype = Object.prototype;
var toStr = ObjectPrototype.toString;
var fnToStr = Function.prototype.toString;
var has = ObjectPrototype.hasOwnProperty;
var isArrowFunction = require('is-arrow-function');
var isDate = require('is-date-object');
Expand Down Expand Up @@ -43,12 +44,15 @@ var isBoolean = function isBoolean(value) {
};
var stringType = '[object String]';
var arrayType = '[object Array]';
var funcType = '[object Function]';
var v8GeneratorFuncType = '[object GeneratorFunction]';
var objType = '[object Object]';

var isFunction = function (type) {
return type === funcType || type === v8GeneratorFuncType;
var isFunction = function (value) {
try {
fnToStr.call(value);
return true;
} catch (e) {
return false;
}
};

module.exports = function isEqual(value, other) {
Expand Down Expand Up @@ -94,17 +98,17 @@ module.exports = function isEqual(value, other) {
return index <= 0;
}

if (isFunction(type)) {
if (!isEqual(value.name, other.name)) { return false; }
if (!isEqual(value.length, other.length)) { return false; }
var valueIsGen = isGenerator(value);
var otherIsGen = isGenerator(other);
if (valueIsGen !== otherIsGen) { return false; }

var valueIsGen = isGenerator(value);
var otherIsGen = isGenerator(other);
if (valueIsGen !== otherIsGen) { return false; }
var valueIsArrow = isArrowFunction(value);
var otherIsArrow = isArrowFunction(other);
if (valueIsArrow !== otherIsArrow) { return false; }

var valueIsArrow = isArrowFunction(value);
var otherIsArrow = isArrowFunction(other);
if (valueIsArrow !== otherIsArrow) { return false; }
if (isFunction(value) || isFunction(other)) {
if (!isEqual(value.name, other.name)) { return false; }
if (!isEqual(value.length, other.length)) { return false; }

var valueStr = String(value);
var otherStr = String(other);
Expand Down

0 comments on commit c7c47c1

Please sign in to comment.