Маленький загрузчик файлов.
Скрипт добавляет две ф-и require, которая загружает файлы и ф-я define - для объявления модулей. Функция require принимает в качестве аргумента массив с путями до файлов модулей, которые необходимо подгрузить.
require(['ajax','dom'], function (obj) { //Объект содержит все модули console.log(obj); });
Ф-я require может подгружать не только модули, которые оформлены в формате AMD, но и обычные js-файлы и библиотеки, а такжы файлы стилей.
require(['js/jquery-2.0.0.min.js', 'css/style.css'], function () { console.log('jQuery и стили были загружены'); });
Функция define занимается объявлением модулей. Получает в качестве аргументов. название модуля, массив названий модулей, от которых зависит и тело модуля.
define('ajax', ['event', 'dom'], function (ajax, event, dom) { ajax.request = function () { console.log('test ajax module'); }; ajax.test = function () { }; console.log(ajax); console.log(event); console.log(dom); return ajax; });
wool-loader ===========
Small loader of files.
The script adds two function require, which loads files and function define - which define module. Function require accepts as argument the array with ways to files of modules, which it is necessary loaded.
require(['ajax','dom'], function (obj) { //Object contains all loaded modules console.log(obj); });
Function require can load not only modules, which are issued in a format AMD, but also usual js-files and libraries, and files of styles.
require(['js/jquery-2.0.0.min.js', 'css/style.css'], function () { console.log('jQuery and styles loaded'); });
Function define define module. Receives as arguments the module name, array names of modules, on which depends and body of module.
define('ajax', ['event', 'dom'], function (ajax, event, dom) { ajax.request = function () { console.log('test ajax module'); }; ajax.test = function () { }; console.log(ajax); console.log(event); console.log(dom); return ajax; });