Info on Drupal.settings and #attached I'm trying to use Drupal.settings for the first time to pass variables from PHP to JavaScript. The documentation on the topic is sparse and I have a few issues.

Is it possible to use #attached to pass through the settings rather than drupal_add_js(array('myModule' =&gt; $settings), 'setting');? The reason I am asking is that I've been told that #attached is the "correct" way to add settings. ( I know it is also the correct way to add files also, but not sure if it works with settings variables.)

I'm using the following code, but I can't get it to load under the DOM objects and I am stuck.

(function ($) {
   Drupal.behaviors.myModule = {
     attach: function(context, settings) {}
   };
});(jQuery);


Any advice would be greatly appreciated. Please bear in mind that this is the first time I've set out to use Drupal.settings, so every detail is welcome and appreciated.
#attached can be used as follows. 

$form['#attached']['js'][] = array(
  'data' =&gt; array(
    'xx_system' =&gt; array(
        'xx_code' =&gt; variable_get('xx_code', 'xx'),
        'xx_key' =&gt; variable_get('xx_key', 'xx'),
      ),
    ),
  'type' =&gt; 'setting',
);


With drupal_add_js(), you can use the following code.

 drupal_add_js(array('orgs' =&gt; $orgs), array('type' =&gt; 'setting'));
 drupal_add_js(drupal_get_path('module', 'module_name') . '/module_name.js');


In a JavaScript file, you can get the value of the variables as follows. 

  Drupal.behaviors.module_name = {
    attach: function (context, settings) {
      var cities = Drupal.settings.orgs.cities;// you will get the cities value here
    }
  };