Requirejs (shim) handles JavaScript libraries that load non-AMD specifications

Source: Internet
Author: User

Using the Requirejs load module, the module is defined to comply with the AMD specification, which defines the module using the following function when defining the module:

 1  define (function   () { 2  var  private = function   { 3  Console.log (' Private party            Fa ... ' );  4  };  5  return   function   () {private ();}  7  };  8 }); 

What if you wanted to embed some of your previous code in Requirejs, even if you included the module code with define, but that code didn't comply with the AMD specification? Don't worry, require config of Shim can help you solve the pain! For example, my file directory structure is as follows:

I want to use the object provided by Framewokr.js in the Quiktip.js file, but Framework.js is not compliant with the AMD specification, in Quiktip.js file require The framework module must first process the following framework.js to conform to the AMD specification, as follows:

1 Require.config ({2BASEURL: ' js/utily ',//Specifies the base path of the JS file3 shim:{4' Framework ': {//This key name is the file name of the target file to be loaded, it cannot be arbitrarily named, otherwise the Framework.js file is not available after the file is not changed to the external interface. Because it's been a hole in my brother's afternoon!!!5Exports: ' Pxjsframe '//The exports value is the name of the external interface provided by Framework.js6             }7         }8     });9Require ([' framework '],function(frame) {Ten     varPxjsframe =frame; OneConsole.log (frame);//This will print the interface objects provided in the framework.js. Ha ha. A}

Requirejs (shim) handles JavaScript libraries that load non-AMD specifications

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.