SEAJS first taste load jquery return null Resolve learning Log

Source: Internet
Author: User

Early this morning tasted seajs, found a very egg-ache thing, using the official demo of jquery is no problem,

Download the official latest version of jquery 2.1.1 found Console.log ($) returned NULL, baffled! Only ask for help Niang!

Yuber's note on GitHub, " methods for calling non-standard modules such as JQuery plug-ins directly "

However, this method in the 2.3 version seems to be no longer, the Seajs.modify method has been removed in this version!

https://github.com/seajs/seajs/issues/286

The standard module here refers to the definition of AMD and CMD.

Quote Yuber in a detailed answer

http://www.zhihu.com/question/20351507/answer/14859415

The following references to Yuber's reply will be more in-depth understanding

 @lifesinger   Yesterday I was too tired, sorry. Later, I used  RequireJs  to solve the problem. In addition, I would like to ask:1. amd  is not easy to get stuck in the UI? Why  2.  is using  NodeJs  modules written in the same  CMD  specification as  seajs   cannot be called directly-I've probably looked at it as if the definition is not quite the same, This is also the problem, since the same specification is followed why the format is not the same,3.  script written with regular global variables is  shim  configured, in  var ejs = require (' Ejs ')   will overwrite  ejs  (global) definition, but can be  require (' Ejs ') directly, then  ejs  will be registered to window  name. 4.  is there any difference between a regular script and a  SeaJs  standard format   and  RequireJs  conversion? In addition, feel requirejs  automatic loading plug-in mechanism is very good. 
@iahuAMD is executed on a load, and when many files are loaded at once, it means that a large number of scripts are executed at once, which can lead to a UI card. The execution of CMD is decentralized and therefore generally does not cause a UI card. SEAJS with node. JS, refer to this document: After #275shim configuration, the Ejs of require (' Ejs ') is the global that Ejs, you can also remove the ejs that is mounted on the window, such as Seajs.config ({plug Ins: ["Shim"], alias: {src: ' path/to/ejs.js ', exports:function () {var ejs = Window.ejs; window.ejs = undefined ; Return Ejs}}) Requirejs shim plugin, essentially the same as SEAJS.

The methods mentioned above are outdated and have to continue to try other ways!

Method One:

Or Yuber the boss of the way "Seajs 2.1.1 removed seajs.modify, how to preload the CDN in jquery?" 》

https://github.com/seajs/seajs/issues/862

The whole article is mainly said not to be modified in the CMD mode in the module using jquery, Yuber boss is not recommended so, but still can achieve

However, the jquery file is not configured in the Seajs.config, is directly in the head header to introduce files, as usual, and then in the Seajs inside an event mechanism to trigger the global jquery object to the internal Module.exports object;

Seajs.on (' exec ', function (module) {if (Module.uri = = = Seajs.resolve (' jquery ')) {window.$ = Window.jquery = Module.exports;}});

Method Two:

Of course, according to the CMD definition to encapsulate a jquery, the method is very simple, as long as the source code to stick in, and then return to jquery object;

Define (function () {//jquery source code return $.noconflict ();});

This allows the introduction of files in the Seajs.config to be used within other modules, here to return why $.noconflict (), see the introduction of the school

Http://www.w3school.com.cn/jquery/core_noconflict.asp
Seajs.config ({base: "). /sea-modules/", alias: {" jquery ":" Jquery.js "}});
Define (function (Require, exports, module) {var $ = require ("jquery"); exports.showobj = function () {Console.log ($);}});

Method Three:

Refer to Seajs official jquery encapsulation method

if (typeof module = = = "Object" && module && typeof Module.exports = = = = "Object") {Module.exports = JQ Uery;} else {if (typeof define = = = "function" && define) {define ("jquery", [], function () {return jquery ;    } ); }}if (typeof window = = = "Object" && typeof window.document = = = "Object") {window.jquery = window.$ = JQuery; }

Download on GitHub

Https://github.com/seajs/examples

In the catalogue sea-modules/jquery there is a packaged version of 1.10;

Finally attach the Seajs plugin development Guide

https://github.com/seajs/seajs/issues/264


SEAJS first taste load jquery return null Resolve learning Log

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.