Skip to content

Commit eb4e888

Browse files
committed
loose instanceof: check constructor function name instead
1 parent ca09849 commit eb4e888

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = function enforce(type, value) {
2626
}
2727

2828
default: {
29-
if (value instanceof type) return
29+
if (value.constructor.toString().match(/function (.*?)\(/)[1] === type.name) return
3030
}
3131
}
3232

test/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var assert = require('assert')
22
var enforceType = require('../src/types')
33

4-
function CustomType() {}
4+
function CustomType() { return "ensure non-greedy match".toUpperCase() }
55

66
var types = ['Array', 'Boolean', 'Buffer', 'Number', 'String', CustomType]
77
var values = [[], true, new Buffer(1), 1234, 'foobar', new CustomType()]

0 commit comments

Comments
 (0)