Skip to content

Using curl.js from a browser console

SimpleAsCouldBe edited this page Mar 22, 2012 · 3 revisions

Executing and defining curl.js modules from a browser console works just fine. This is handy, because it is a great way to demonstrate to colleagues how beautifully decoupled curl allows you to make your JavaScript.

To load and execute a module you have already defined, use the normal curl bootstrap syntax:

curl(['components/lightbox'], function(lightbox){
	lightbox('hello');
});

If you want to create a module and execute it, make sure you specify a module Id. Since console defined modules don't have a filename, this is the only way curl can find the module.

define( 'newLightbox' // module id (this is the important bit)
,	function () {
	var lightbox = function (displayString) {	
		alert(displayString);
    };
    return lightbox;
});

curl(['newLightbox'], function(lightbox){
	lightbox('hello');
});

## ### 1.

Clone this wiki locally