Skip to content

Instantly share code, notes, and snippets.

@heartforit
Created October 16, 2022 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heartforit/1bda829c1b12bb2dcdecd02fd8ecc071 to your computer and use it in GitHub Desktop.
Save heartforit/1bda829c1b12bb2dcdecd02fd8ecc071 to your computer and use it in GitHub Desktop.
Check for arrow function / lambda in javascript
function isLambda(func){
if(typeof func !== "function") throw new Error("invalid function was provided")
let firstLine = func.toString()
.split("\n")['0']
.replace(/\n|\r|\s/ig, "")
return (!firstLine.includes("function") && (firstLine.includes(")=>{") || firstLine.includes("){")))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment