File tree Expand file tree Collapse file tree 3 files changed +43
-1
lines changed
Expand file tree Collapse file tree 3 files changed +43
-1
lines changed Original file line number Diff line number Diff line change 1010
1111### Features
1212
13+ - [ ` dfaac0e ` ] ( https://github.com/stdlib-js/stdlib/commit/dfaac0e5abda104d28e86b0ef5c10ef2b20102b2 ) - add support for ` Symbol.hasInstance `
1314- [ ` d7e5431 ` ] ( https://github.com/stdlib-js/stdlib/commit/d7e5431a210b9e0ccf1e55485235e1a3ae725de3 ) - add ` hasHasInstanceSymbolSupport ` to namespace
1415- [ ` 168c234 ` ] ( https://github.com/stdlib-js/stdlib/commit/168c23482effd51fbc51be8c25036e6b9ad66f47 ) - add ` assert/has-has-instance-symbol-support `
1516- [ ` aad9fb9 ` ] ( https://github.com/stdlib-js/stdlib/commit/aad9fb90278125579b2627f502fcce1da45c283c ) - add ` hasIsConcatSpreadableSymbolSupport ` to namespace
@@ -129,6 +130,7 @@ A total of 19 issues were closed in this release:
129130
130131<details >
131132
133+ - [ ` dfaac0e ` ] ( https://github.com/stdlib-js/stdlib/commit/dfaac0e5abda104d28e86b0ef5c10ef2b20102b2 ) - ** feat:** add support for ` Symbol.hasInstance ` _ (by Athan Reines)_
132134- [ ` d7e5431 ` ] ( https://github.com/stdlib-js/stdlib/commit/d7e5431a210b9e0ccf1e55485235e1a3ae725de3 ) - ** feat:** add ` hasHasInstanceSymbolSupport ` to namespace _ (by Athan Reines)_
133135- [ ` 168c234 ` ] ( https://github.com/stdlib-js/stdlib/commit/168c23482effd51fbc51be8c25036e6b9ad66f47 ) - ** feat:** add ` assert/has-has-instance-symbol-support ` _ (by Athan Reines)_
134136- [ ` 5f5bb2d ` ] ( https://github.com/stdlib-js/stdlib/commit/5f5bb2d4277a24000b57fb07bc28d821500cd7e8 ) - ** docs:** update namespace table of contents [ (#8425 )] ( https://github.com/stdlib-js/stdlib/pull/8425 ) _ (by stdlib-bot, Athan Reines)_
Original file line number Diff line number Diff line change 2020
2121// MODULES //
2222
23+ var hasHasInstanceSymbolSupport = require ( './../../has-has-instance-symbol-support' ) ; // eslint-disable-line id-length
24+ var HasInstanceSymbol = require ( '@stdlib/symbol/has-instance' ) ;
2325var format = require ( '@stdlib/string/format' ) ;
2426
2527
28+ // VARIABLES //
29+
30+ var hasSupport = hasHasInstanceSymbolSupport ( ) ;
31+
32+
2633// MAIN //
2734
2835/**
@@ -55,7 +62,14 @@ var format = require( '@stdlib/string/format' );
5562*/
5663function instanceOf ( value , constructor ) {
5764 // TODO: replace with `isCallable` check
58- if ( typeof constructor !== 'function' ) {
65+ if (
66+ typeof constructor !== 'function' &&
67+ ! (
68+ hasSupport &&
69+ typeof constructor === 'object' &&
70+ typeof constructor [ HasInstanceSymbol ] === 'function'
71+ )
72+ ) {
5973 throw new TypeError ( format ( 'invalid argument. Second argument must be callable. Value: `%s`.' , constructor ) ) ;
6074 }
6175 return ( value instanceof constructor ) ;
Original file line number Diff line number Diff line change 2121// MODULES //
2222
2323var tape = require ( 'tape' ) ;
24+ var isArray = require ( './../../is-array' ) ;
25+ var hasHasInstanceSymbolSupport = require ( './../../has-has-instance-symbol-support' ) ; // eslint-disable-line id-length
26+ var HasInstanceSymbol = require ( '@stdlib/symbol/has-instance' ) ;
2427var inherit = require ( '@stdlib/utils/inherit' ) ;
2528var Boolean = require ( '@stdlib/boolean/ctor' ) ;
2629var Function = require ( '@stdlib/function/ctor' ) ;
@@ -29,6 +32,13 @@ var Object = require( '@stdlib/object/ctor' );
2932var instanceOf = require ( './../lib' ) ;
3033
3134
35+ // VARIABLES //
36+
37+ var opts = {
38+ 'skip' : ! hasHasInstanceSymbolSupport ( )
39+ } ;
40+
41+
3242// TESTS //
3343
3444tape ( 'main export is a function' , function test ( t ) {
@@ -176,3 +186,19 @@ tape( 'the function returns `false` if provided primitives and their correspondi
176186
177187 t . end ( ) ;
178188} ) ;
189+
190+ tape ( 'the function supports ES2015+ environments supporting `Symbol.hasInstance`' , opts , function test ( t ) {
191+ var bool ;
192+ var obj ;
193+ var x ;
194+
195+ x = [ 1 , 2 , 3 ] ;
196+
197+ obj = { } ;
198+ obj [ HasInstanceSymbol ] = isArray ;
199+
200+ bool = instanceOf ( x , obj ) ;
201+ t . strictEqual ( bool , true , 'returns expected value' ) ;
202+
203+ t . end ( ) ;
204+ } ) ;
You can’t perform that action at this time.
0 commit comments