RequireJS can be added to a web page with a simple script tag, as in the previous example. The important thing about this script tag is that it must have a data-main attribute to point to the starting point of the JavaScript.
In this example, we determine the starting point as scripts/main, require() method adds the missing .js extension, and loads the scripts/main.js file.
- First of all, we'll develop the todo.js file as follows:
define(function () { var list = []; return { add: function (item) { list.push(item); }, renderList: function() { var html = ''; for (var iLoop = 0, len = list.length; iLoop < len; iLoop++){ html += '<li class="list-group-item">' + list[iLoop] + '</li>'; } return html; } }; });
The todo.js file ...