javascript - How do convert this module pattern to require.js? -
i made module pattern in javascript, can create modules , use them whenever want to. don't know how can convert require.js. each of modules, i.e. trades.togglemenu, trades.tabs, etc, in separate files. included them here make story short so. please help:
js:
(function (window, $) { var trades = (function(trades) { // modules should initialised here. produdction, use module dependency library, e.g. require.js trades.main = function() { this.togglemenu(); this.validation.run($('#registration-form, #homeowner-login-form, #tradesmen-login-form')); this.tabs(); }; trades.togglemenu = function() { }; trades.tabs = function(el) { }; trades.vaildation = function(el) { return { run: function (formname) { //do something... } }; }; return trades; }(trades || {})); window.trades = trades; $(function() { trades.main(); }); }(window, jquery));
many thanks
you have file called trades.js defines "trades" module:
define(["jquery"], function ($) { var trades = (function(trades) { ... return trades; }(trades || {})); return trades; });
and use follows:
require(["jquery", "trades"], function ($, trades) { $(function() { trades.main(); }); });
jquery configured module either using requirejs/jquery combo file (http://requirejs.org/docs/jquery.html#get) or defining path jquery in answer (require.js shim config global scope?).
Comments
Post a Comment