diff --git a/lib/ClassBuilder.js b/lib/ClassBuilder.js index fb657c8..532b70f 100644 --- a/lib/ClassBuilder.js +++ b/lib/ClassBuilder.js @@ -230,6 +230,11 @@ exports.isInstanceOf = function( type, instance ) { var meta, implemented, i; + if ( !( type && instance ) ) + { + return false; + } + try { // check prototype chain (will throw an error if type is not a diff --git a/test/test-class.js b/test/test-class.js index 5c76b4f..b8a4a07 100644 --- a/test/test-class.js +++ b/test/test-class.js @@ -102,6 +102,16 @@ assert.ok( "Class instance is recognized by Class.isInstanceOf()" ); +assert.ok( + Class.isInstanceOf( Foo, undefined ) === false, + "Checking instance of undefined will not throw an error" +); + +assert.ok( + Class.isInstanceOf( undefined, {} ) === false, + "Checking for instance of undefined will not throw an error" +); + assert.ok( !( Class.isInstanceOf( Foo, Foo ) ), "Class is not an instance of itself when uninstantiated"