Skip to content

Instantly share code, notes, and snippets.

@johnkpaul
Created June 24, 2011 02:04
Show Gist options
  • Save johnkpaul/1044075 to your computer and use it in GitHub Desktop.
Save johnkpaul/1044075 to your computer and use it in GitHub Desktop.
Add to JavaScript function prototype ability to find source in file
if(typeof _scriptsRecorded == "undefined"){
var scriptBodies = {}
var scripts = document.querySelectorAll("script");
for(var i = 0, len = scripts.length;i<len;i++){
var script = scripts[i];
(function(src){
$.get(src, function(data){
scriptBodies[src] = data;
})
})(script.src)
}
}
_scriptsRecorded = true;
Function.prototype.findFile = function(){
var source = this.toSource();
for(var key in scriptBodies){
var script = scriptBodies[key];
if(script.indexOf(source) > -1){
return key;
}
}
}
@johnkpaul
Copy link
Author

Currently this assumes jQuery is present, but I would like to remove that requirement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment