Parameterized JavaScript

Wouldn't it be nice if you could pass parameters to your JavaScript file? Well, it turns out you can.

I have tested the method described here in Chrome, FireFox, InternetExplorer, and Safari.

index.html

<!DOCTYPE html>  
<html>  
  <head>
    <title>Arguments Demo</title>
    <script src="arguments.js" spinner="spinner.png"></script> 
  </head>
  <body>
  </body>
</html>  

arguments.js

if(!NSArguments) {  
  var Arguments = function() {
    var self = {
      script: document.currentScript || document.scripts[document.scripts.length-1]
    };
    var that = {};
    that.getArgument = function(name) {
      return self.script.getAttribute(name);    
    };
    return that;
  };
  var NSArguments = Arguments();
}

(function(){
    window.addEventListener("load", function() {
      var spinner = NSArguments.getArgument("spinner");
      console.log(spinner);
    });
}());

The output in the console will be:
Screenshot