Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Last active March 27, 2021 18:25
Show Gist options
  • Save WebReflection/dc3965e704312b3d613d to your computer and use it in GitHub Desktop.
Save WebReflection/dc3965e704312b3d613d to your computer and use it in GitHub Desktop.
a runtime feature detection way to sniff native functions from fakes
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