What is the purpose of url('', array('prefix' => &$prefix)) in drupal_add_js()? I was looking at the code of drupal_add_js(), and noticed the following code.

  // url() generates the prefix using hook_url_outbound_alter(). Instead of
  // running the hook_url_outbound_alter() again here, extract the prefix
  // from url().
  url('', array('prefix' =&gt; &amp;$prefix));


I tried executing the following code, from the Devel module.

dsm(url('', array('prefix' =&gt; &amp;$prefix)));
dsm($prefix);


The output was "/dr72/" for the first dsm(), but nothing for the second one.

Looking at the HTML of the front page in my test page, I notice the following JavaScript code.

jQuery.extend(Drupal.settings, {"basePath":"\/dr72\/","pathPrefix":"", /* … */ });


What is the purpose of that code in drupal_add_js() work? How it is supposed to work?
Modules can implement hook_url_outbound_alter() to change to change generated URL's. The most typical example of that are language prefixes.

If you have two languages enabled with path prefixes, english at /en and german at /de, then pathPrefix will either be /de or /en. Since there is no actual API to get that prefix, it uses that trick.

The hook invokes locale_url_outbound_alter(), which in turn invokes the defined url_rewrite callbacks of the enabled language negotation types. In case of the path prefix, that is locale_language_url_rewrite_url which changes the prefix at the end of the function.

The reason for doing this is that it allows ajax calls and other javascript requests (for example the admin overlay) to do that request in the current language, so that strings returned by those requests are in the expected language.