Modular Development (II)---SEAJS Introductory learning

Source: Internet
Author: User
Tags define function

SEAJS is an implementation of a module system loader [CMD specification] (HTTPS://GITHUB.COM/CMDJS/SPECIFICATION/BLOB/MASTER/DRAFT/MODULE.MD) 9, based on the CMD module definition specification. SEAJS callback function of the startup function official website: Http://seajs.org/docs/github:https://github.com/seajs/seajs How to choose a technology product stack:-Whether it is Daniel-see if the community is active- To see if the author of the regular update seajs has not updated the project, but many companies in the country are still using SEAJS as a front-end modular solution, learning Seajs helps us learn the module systems in node. JS because they use the same specifications. After studying SEAJS, you can teach yourselfRequirejs[requirejs official Website] (http://requirejs.org/), the idea is basically the same. Is nothing more than the difference between APIs. # # # Experience Official demo[Official sample Demo] (http://seajs.org/docs/#quick-start) # # #seaJs使用步骤: 1. Download Sea.js Library 2. Introduce sea.js3 in the page. Define-Define Module 4. Module.exports-Exposed interface 5. Require-load Module 6. Seajs.use-Boot the module system from the Ingress module Seajs.use ('./././', function (a) {Console.log (a);//    }10, define () usage:    Define (object)     define (string)     Define (function ( Require,exports,medule) {       //All your own JS code is written in the callback function     })     Example 1:      define (function (Require, exports, module) {   //best to use anonymous functions and pass in three parameters every time the module is defined Do not rename the Require function;            module.exports = {   //The object is burst out of the module in this form For other files, can be used directly exports = ...                    Add:require ('./././'),  //require's parameter value must be a string, which is a module identifier for the module           &NB sp;         Mod:require ('./././')    //access using mod () direct call    &nbs p;       }   })     example 2:    define (function (require, exports, module) {        &nbsp   Exports.add = Reuire ('./././');   //access needs to be called via Exports.add ()        & nbsp;    Exports.mod =require ('./././');   }) 11, require ('./././') loading file modules          Best of all require are written in the Define function in the top of the JS code         [require Writing Convention] (https:// github.com/seajs/seajs/issues/259) 12, Seajs in the page:        First load sea.js file           then start the module:<script> </script> tag to load the Ingress module Seajs.use ('./a ')               Boot module system----Boot              The Seajs.use method is to asynchronously load the module file 13, the module ID: In fact, the path of the module, can not include the file suffix name, because the load is JS file         relative identity: to./or. /starts with relative identification, relative to the file that is currently present in the location         top-level identity: not with./or. /or/or the start of the identity is the top-level identity, the top-level identity is resolved relative to the module system's underlying path, and the underlying path of the module system is not specified,             The default top-level directory is a third-party plug-in Sea.jsIn the directory, you can specify the base path of the top-level identity by using the Seajs.config () method             Top-level identity configuration: Seajs.config ({                 Base: './'  ; Specify current directory as top-level directory              })        module identifies the file path that always appears relative to require. 14, Require.async ('./file ') implement asynchronous conditional loading         if (true) {require ('./a ')}else{require ('./b ')} At this point A and B files will be loaded         require is all loaded successfully before parsing and execution         Require.async can be loaded according to conditions, and the code will load and execute when it executes to a specific location          if (true) {                 Require.async ('./b ', function (foo) {                    Console.log (foo);  //Foo is the content shown in the./b file                 })          }else {                Require.async ('./a ', function () { }  )          }15, exports and module  &nbs p;     Module.exports is the interface object that the module exports externally, which is equivalent to executing the return module.exports        Exports is module.exp.An alias for Orts.         module.exports is the interface object between the current module and the external file.     First need to understand:        var  foo2 = {}        var Foo3 =foo2  &nbsp ;     foo3.name = ' name '//This is modified Foo3, its references are also modified         Console.log (FOO2)       & nbsp Console.log (Foo3)         Foo3 = ' Hello '  //This is the re-assignment of Foo3, the original Foo2 reference was lost       &NBSP ; Console.log (Foo2)         Console.log (FOO3)     then:        var foo ={&nbsp ;           obj: {}       }        function Changefoo (obj , foo) {            Console.log (obj===foo.obj)//true            Obj.name = ' Jack '             obj = ' Hello '             Console . log (Obj===foo.obj)  //false           return foo.obj       }        Console.log (Changefoo (Foo.obj, FOO)///{name:jack}    last:        obj is equivalent to Exports,foo equivalent to module. To sum up, we can not give exports re-assignment, so cut off the connection between exports and module.exports, you must change the value of exports through the form of a point. 16. What does JS in the browser not do?         cannot manipulate the database, cannot manipulate the file, the browser's JS can only send the request through the Ajax, cannot accept the request (later socket network programming can carry on two-way communication)          JS can be run from the browser alone (this time there is no BOM and DOM), JS is only a language (previously learned JS is just ECMAScript)  

Modular Development (II)---seajs Introductory learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.