模块化开发:AMD(Asynchronous Module Definition) 7 /* wrapper */ define( /*module id*/ 'myModule', /*dependencies*/ ['foo','bar','foobar'], /*definition for the module export*/ function (foo, bar, foobar) { /*module object*/ var module = {}; /*module methods go here*/ module.hello = foo.getSomething(); module.world = bar.doSomething(); /*return the defined module object*/ return module; } ); /* top-level: the module exports (one, two) are passed as function args to the callback.*/ require(['one', 'two'], function (one, two) { }); /* inside: complete example */ define('three', ['one', 'two'], function (one, two) { /*require('string') can be used inside the function to get the module export of a module that has already been fetched and evaluated.*/ var temp = require('one'); /*This next line would fail*/ var bad = require('four'); /* Return a value to define the module export */ return function () {}; }); 7 12年6月16日星期六
模块化开发:Require.js 8 requirejs.config({ //By default load any module IDs from js/lib baseUrl: 'js/lib', //except, if the module ID starts with "app", //load it from the js/app directory. paths //config is relative to the baseUrl, and //never includes a ".js" extension since //the paths config could be for a directory. paths: { app: '../app' } }); 8 12年6月16日星期六
模块化开发:Require.js 9 //my/shirt.js now has some dependencies, a cart and inventory //module in the same directory as shirt.js define(["./cart", "./inventory"], function(cart, inventory) { //return an object to define the "my/shirt" module. return { color: "blue", size: "large", addToCart: function() { inventory.decrement(this); cart.add(this); } } } ); 9 12年6月16日星期六
Backbone Router 和 jQuery Mobile Ajax navigator 16 Single Page Application ( SPA ) : AJAX + # Backbone routers are used for routing your applications URL's when using hash tags(#). Backbone.Router provides methods for routing client- side pages, and connecting them to actions and events. 16 12年6月16日星期六
Backbone Router 和 jQuery Mobile Ajax navigator 16 Single Page Application ( SPA ) : AJAX + # Backbone routers are used for routing your applications URL's when using hash tags(#). Backbone.Router provides methods for routing client- side pages, and connecting them to actions and events. jQuery Mobile: “All navigation within jQuery Mobile is based on changes and updates to location.hash. Whenever possible, page changes will use a smooth transition between the current "page" and the next, whether it is either already present in the DOM, or is automatically loaded via Ajax.” 16 12年6月16日星期六