From bb98c9afb320df4d0bff875ba89cac1f2c323b95 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 21 Apr 2014 22:22:42 -0400 Subject: [PATCH] Revert "Removed unnecessary try/catch from isInstanceOf" This reverts commit 58ee52ad4a0ebf51f9add9b99188968268ed6f8e. As it turns out, IE9 allows use of instanceof with special object types, not just functions. One such example is HTMLElement; its type is `object', whereas in Firefox and Chromium it is `function'. There is no reliable way to perform this detection. Therefore, the try/catch here is more reliable. --- lib/ClassBuilder.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/ClassBuilder.js b/lib/ClassBuilder.js index 74f2dc4..0b760aa 100644 --- a/lib/ClassBuilder.js +++ b/lib/ClassBuilder.js @@ -244,14 +244,16 @@ exports.isInstanceOf = function( type, instance ) return false; } - // check prototype chain (will throw an error if type is not a - // constructor (function) - if ( ( typeof type === 'function' ) - && ( instance instanceof type ) - ) + try { - return true; + // check prototype chain (will throw an error if type is not a + // constructor (function) + if ( instance instanceof type ) + { + return true; + } } + catch ( e ) {} // if no metadata is available, then our remaining checks cannot be // performed