Last active
March 27, 2021 18:25
-
-
Save WebReflection/dc3965e704312b3d613d to your computer and use it in GitHub Desktop.
a runtime feature detection way to sniff native functions from fakes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isNativeFunction = (function (Function) { | |
var | |
toString = Function.toString, | |
re = new RegExp( | |
'^' + | |
toString | |
.call(Function) | |
.replace(/([\/\\[\]{}()^$.*+?_-])/g, '\\$1') | |
.replace('Function', '[a-zA-Z$_][\\S]*') + | |
'$' | |
) | |
; | |
return function (fn) { | |
return re.test(fn); | |
}; | |
}(Function)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment