Question

I have a load of code, and I think much of it is deprecated with numerous methods that are never called. I would like to know which methods in this code will never be called, either as a result of button clicks or via other methods. I could go through and comment out the suspicious methods one-by-one and test the code, but is there a better way?

I am using Visual Studio 2012, and I have tried using JS Lint but that doesn't seem to tell me what I want to know. I really like the Code Analysis for C# and SQL that VS2012 does, but it doesn't do this for Javascript. What should I use?

Was it helpful?

Solution

Open your JS file as the script in a webpage in Chrome. Just surround your JS with an html and script tag:

<html><script>
var mycode = goeshere();
</script></html>

Once you open it in chrome, right click anywhere on the page and click 'Inspect Element'. Alternatively you can just press CTRL+SHIFT+J to bring up the console.

Once the pane opens, click on the 'Profiles' tab.

Select "Collect JavaScript CPU Profile", and follow the steps to run it.

This will give you timing counts per function call. Try to work through as much of the functionality as you can, then once you are finished look at the function timing counts. Any call with 0 time probably wasn't called. This should at least give you a starting point.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top