Requirejs Shim Usage Notes

Source: Internet
Author: User

If the AMD specification is used in Requirejs, there are not many problems in using it, and if you load a JS file that is not an AMD specification, you will need to use shim in require.

Require.config ({    paths:{        jquery: "/js/jquery2.0",        instorage: "/js/in/instorage",        Product: "/js/ Product/product ",        Cate:"/js/product/category ",    },    shim:{        cate:{            deps:[],            exports:" Category "        }}}    );

Cate: "/js/product/category" This file is non-AMD specification JS, in the process of using to follow the following several steps:

(1) Paths in the configuration file loading path, JSON key value can be arbitrary, as meaningful as possible, the value in JSON is the file loading path, this needless to say

(2) A JSON object is defined in shim, and the Key value (Cate) is the same as the name defined in paths

(3) The JSON object in Shim has two properties: deps,exports; Deps An array that represents the library it relies on, and exports represents the object name of the output

var category= (function () {    var param={};    Param. Add=function () {        console.log ("new category");    }    return param;}) (); var category= (function (param) {    param. Write=function () {        console.log ("Output classification information");    }    return param;}) (category| | {});

Requirejs can realize the delay loading of JS, loading JS When the method is called, that is, require the information of a module in function.

Define (function () {    var productmanager={        create:function () {            Console.log ("Create Product");            Require (["Cate"],function (Cate) {                cate. Write ();                Cate. Add ();            });        }    }    return productmanager;});

(EXT) Requirejs shim usage notes

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.