Skip to content
Nathan Rijksen edited this page Aug 13, 2015 · 5 revisions

Komodo 9 introduces the require('module') function (CommonJS specification) to be able to load JavaScript files on demand.

Example:

var logging = require("ko/logging");

You can find available modules here: https://github.com/Komodo/KomodoEdit/tree/master/src/chrome/komodo/content/sdk

For example you can get the language of the current file:

var language = require("ko/editor").getLanguage();

Function getLanguage() defined in editor.js: https://github.com/Komodo/KomodoEdit/blob/master/src/chrome/komodo/content/sdk/editor.js#L604

Add-ons

Add-ons can define their own require names by adding a special require-path xpcom category entry into their chrome.manifest file:

category require-path commando chrome://commando/content/js/

and then they make use of their JS modules like so:

var proj = require("commando/project");

which would map to the chrome://commando/content/js/project.js file.

APIs

Komodo's require functionality is built on top of the Mozilla Addon SDK, so nearly all of the APIs defined there can be used inside of Komodo. I say nearly, as some things are obviously different (e.g. the Firefox browser has web page tabs).