Two JS files attached to one module Alright, so I have two files which should be added to a module. This is the way I do it:

$form['display']['#attached'] = array(
    'js' =&gt; array(
      array('data' =&gt; drupal_get_path('module', 'test_module') . '/js/test_module.js'),
      array('data' =&gt; drupal_get_path('module', 'test_module') . '/js/common.js'),
    ),
  );


Now my test_module.js file looks like this:

(function ($) {
Drupal.behaviors.test_module = {
  attach: function(context) {
    console.log(Drupal.settings);
  }
}});


And js works fine because I get data from Drupal.settings object. However, the second one is totaly the same and console.log does not work. Here's how it looks:

(function ($) {
    Drupal.behaviors.test_module = {
      attach: function(context) {
        console.log("test data");
      }
    }});


Why the second file does not work?
Don't duplicate the attach function.

(function ($) {
Drupal.behaviors.test_module = {
  attach: function(context) {
    console.log(Drupal.settings);
  }
}})(jQuery);


If you have used this for 1st JS

(function ($) {
Drupal.behaviors.test_module_2 = {
  attach: function(context) {
    console.log("test data");
  }
}})(jQuery);


Then you can use this for 2nd JS as the attach function should be used only once