0

I'm using the so called garber-irish technique for splitting up my javascript files.

My question is, I have a Model (Item say) and have an init function which is in app/assets/javascripts/item/item.js

e.g.

MYAPP.items = {
  init: function() {
    alert("do something");
  }
};

Now.. lets say I have an administration side to this app, and I don't really want to include the admin javascript in the main bulk. So.. I have a different system_adminstration.js which requires the regular javascripts/item/item.js above, but also requires a javascripts/admin/item/item.js which would look something like:

MYAPP.items = {
  init: function() {
    alert("also do this");
  }
};

I want to load both the common javascripts above, and the administation specific ones - effectively merging the two init functions and keeping things nicely dry.

Questions:

  1. Is this a sensible approach?
  2. It it possible?
Community
  • 1
  • 1
patrickdavey
  • 1,966
  • 2
  • 18
  • 25

1 Answers1

0

Keen for comments - but what I have done (for the moment) is change the init function to :

UTIL.exec( "common" );
UTIL.exec( controller );
UTIL.exec( "admin_"+controller );
UTIL.exec( controller, action );
UTIL.exec( "admin_"+controller, action );

(so, I'm adding in an "admin_") and then for the admin javascript files I've simply added in an admin prefix:

MYAPP.admin_items = {
  init: function() {

....

Slightly nasty but I think it'll do me until someone has a nicer suggestion!

patrickdavey
  • 1,966
  • 2
  • 18
  • 25