Wiki Markup |
---|
{float:right|background=#eee}
{contentbylabel:title=Related Articles|showLabels=false|showSpace=false|space=@self|labels=javascript}
{float} |
JavaScript Modules are a mechanism for bringing modern concepts of variable scope and dependency management to JavaScript. Starting with version 5.4, Tapestry uses RequireJS modules internally, and provides support for using RequireJS modules in your own Tapestry application.
Div | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
|
The Need for Modules
As web applications have evolved, the use of JavaScript in the client has expanded almost exponentially. This has caused all kinds of growing pains, since the original design of the web browser, and the initial design of JavaScript, was never intended for this level of complexity. Unlike Java, JavaScript has no native concept of a "package" or "namespace" and has the undesirable tendency to make everything a global.
...
Code Block | ||||
---|---|---|---|---|
| ||||
(function() { define(["jquery", "./events", "./dom", "bootstrap/modal"], function($, events, dom) { var runDialog; runDialog = function(options) { ... }; $("body").on("click", "[data-confirm-message]:not(.disabled)", function() { ... }); dom.onDocument("click", "a[data-confirm-message]:not(.disabled)", function() { ... }); return { runDialog: runDialog }; }); }).call(this); |
Info |
---|
The above code is actually the compiled output of a CoffeeScript source file. The |
...
If you are using the optional tapestry-web-resources
module (that's a server-side module, not an AMD module), then you can write your modules as CoffeeScript files (or TypeScript, starting in Tapestry 5.5); Tapestry will take care of compiling them to JavaScript as necessary.
...
In development mode, Tapestry will write details into the client-side console.
This lists modules explicitly loaded (for initialization), but does not include modules loaded only as dependencies. You can see more details about what was actually loaded using view source; RequireJS adds <script>
tags to the document to load libraries and modules.
...