Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

This page contains recommended conventions for Javascript Development.

Namespacing

It's a good idea to namespace any functions, objects, or other Javascript variables you include in your code in order to avoid name collisions with other parts of OpenMRS, or any 3rd party javascript libraries we include.  If you're working on a module you can use openmrs.module_id for your namespace.  A simple way to achieve this, using the reporting module as an example, is with the following idiom that can be included at the top of the javascript for any page.

var openmrs = openmrs || {};
openmrs.reporting = openmrs.reporting || {};

// Now use the namespace for functions, etc
openmrs.reporting.triggerReport = function(args) { };

References

Even though it's a few years old, Crockford's Javascript: The Good Parts is still likely required reading. It's also really short and it a quick read.

  • No labels