2

I'd like to programatically find all javascript functions and add some code for profiling purposes (to count how many times they are called). Is there any existing tool or a regex to do that?

It is relatively easy to write something like:

function\s+\w+\(.*?\)\s*{

But that only begins to cover the multitude of options.

2
  • 1
    There can be newlines as well before and after ( or ) Commented Jun 1, 2017 at 16:37
  • 2
    With ES6, method fonctions no longer need the keyword function. I mean obj={fn() {}}. I don't think there's a way to find these with regex, you would need a Javascript parser. Commented Jun 1, 2017 at 16:40

2 Answers 2

2

I have tried something similar and came to the result that a regex is not the weapon of choice for that.

But I would recommend you to have a look here and create a Plugin for Babel. In step 3 »generation« you can probably modify all functions.

Sign up to request clarification or add additional context in comments.

Comments

0

Using Google Chrome (assuming universal compliance)...

  1. Hit F12 to open developer console
  2. Find the "Performance" tab and click on it.
  3. Hit record or Ctrl + E to start / stop recording. Chrome will give you everything you need to know. :3

(PS. Just sell your soul to Google! ^w^)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.