Skip to content

Commit

Permalink
Improve optimization by separating the try/catch, and bailing out ear…
Browse files Browse the repository at this point in the history
…ly when not typeof "object".
  • Loading branch information
ljharb committed Jan 29, 2015
1 parent c278e21 commit 5ab7632
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var regexExec = RegExp.prototype.exec;

module.exports = function isRegex(value) {
var tryRegexExec = function tryRegexExec(value) {
try {
regexExec.call(value);
return true;
Expand All @@ -11,3 +11,7 @@ module.exports = function isRegex(value) {
}
};

module.exports = function isRegex(value) {
if (typeof value !== 'object') { return false; }
return tryRegexExec(value);
};

0 comments on commit 5ab7632

Please sign in to comment.