Skip to content

A very very small module loader that runs on top of jQuery.

Notifications You must be signed in to change notification settings

ropbla9/wagon-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

Description

Wagon.js is a very small module loader (1.4k) that tuns on top of jQuery. It has very simple usage and you don't need to use any additional wrapper to require.

Its syntax may please either CommonJS or AMD users.

Usage

Firstly, call jQuery by <script>, right after call wagon.min.js.

Creating the module

// modules/myModule.js

var dependencie = Wagon.require('modules/dependence.js') // this module inherits from another

var private = 'private var value';
var public = 'public var value';

var inheritFromDependencie = dependencie.public; // inherits var from dependencie

function privateFunction(a, b) {
	return a + b;
}

function publicFunction() { // public function that shows internal vars
    console.log(private);
    console.log(privateFunction(1, 1));
}

var wrapper = { // wrap your public vars on a plain object or function
	public: public,
    publicFunction: publicFunction,
    inheritFromDependencie: inheritFromDependencie
}

Wagon.exports(wrapper) // IMPORTANT: this method accepts ONLY ONE ARGUMENT and it must be a PLAIN OBJECT or a single FUNCTION

Requiring the module and defining path's

// index.html

Wagon.setModule("myModule", "modules/myModule.js"); // optional path shotcurt

var myModule = Wagon.require("myModule"); // you can write full path or just type the modules name relative to path as its setted above

myModule.publicFunction() // logs 2 and "private var value";
console.log(myModule.public) // logs "public var value"
console.log(myModule.inheritFromDependencie) // logs inherited var pro dependencie
	     

About

A very very small module loader that runs on top of jQuery.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published