1

I am attempting to locate where a particular class/function/object is defined on a site with many javascripts being rendered. Manually sifting through the scripts has proven to be very time consuming in the 'Scripts' panel of Firebug.

Before I continue going that route, is there an easier way using modern front-end development tools to locate where certain things are defined? Would be great if I had some kind of ctags type functionality that vim provides, but any other approach would be great.

3
  • I'd like to know this, too. It would be especially handy when answering SO questions, since I don't know what's going on in the questioner's site. Commented Apr 25, 2013 at 20:38
  • What do you mean by "class"? A function? Commented Apr 25, 2013 at 20:40
  • I've edited my question. class/function/object, whatever. If someone even has a simple object definition of a = {}; and later uses a.bar = "foo", I'd love to be able to go back to find what file the a in current scope was defined in. Commented Apr 25, 2013 at 20:42

2 Answers 2

1

Chrome has Find in all Sources:

CTRL-SHIFT-F on Windows and CMD-OPT-F on Mac.

Edit:

You can also use CMD-SHIFT-O (mac) CTRL-SHIFT-O (windows/linux) in chrome to find functions by name.

enter image description here

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

1 Comment

In Firebug you can search via Ctrl+F/⌘+F.
0

AFAIK none of the standard dev tools (Chrome Debugger, Firebug, etc.) offer this functionality. You can sort of get it by typing the object's name in the Chrome debugger, but that will just show you something like "Backbone.View.extend.extend.constructor". In other words, it shows you the root-most constructor, which is fine if all your classes are exactly one level deep. If not though, for instance if A is a subclass of B and B is a subclass of C, knowing that your object "a" comes from C doesn't really help much.

Furthermore, even if it is what you want, Chrome won't tell you where to find the constructor, just its name. Personally I solve this by giving all my objects a _type property (or attribute, for the ones that are Backbone models). This way I can simply type myObject._type (or myObject.get('_type') for the models) and know what kind of object I have. And since I give every object type a unique name, all it takes to find the cunstructor is grep for that name.

2 Comments

Thanks for this information. I suppose the problem is, I see an attribute being used over and over and I cannot find where there was an assignment made to it. It's a site's source that I don't own, which makes it even worse.
Right. None of the tools does let you jump from a function call or a variable usage to it's definition at the moment. I created an issue for Firebug covering this a while back.

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.