Skip to content

Instantly share code, notes, and snippets.

@cocoabox
Last active July 14, 2016 13:21
Show Gist options
  • Select an option

  • Save cocoabox/21da690ef2529b7a84f160967a8f8aa6 to your computer and use it in GitHub Desktop.

Select an option

Save cocoabox/21da690ef2529b7a84f160967a8f8aa6 to your computer and use it in GitHub Desktop.
JS でとある関数が nativeかどうか判定する
/**
* detect if function is native
* @param {function} func
* @return {boolean|null} returns true if func is native, false if not, or null if func is not a function
*/
var isNative = function(func){
return typeof func!=="function"
?null
:(null!==(""+func.toString()).match(/^\s*function\s*([^\s]+)\s*\{\s*\[native code\]\s*\}\s*$/));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment