Why isn't RequireJS passing jQuery into the functions alias?

后端 未结 3 933
一整个雨季
一整个雨季 2021-02-09 09:36

I downloaded the sample-project for the latest-release of RequireJS. Their documentation implies anything loaded is passed-into the parameter list of the associated function (i

3条回答
  •  走了就别回头了
    2021-02-09 10:41

    jQuery should be loaded through the special name "jquery", otherwise it won't register itself (since jQuery uses a named define).

    // create an alias that points to proper file
    require.config({
      paths : {
        jquery : "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min"
      }
    });
    
    // require jquery usign the path config
    require(["jquery"], function ($) {
        console.log($);
    });
    

    That is the main reasons why named define is considered an anti-pattern and should be used only when needed (when you have multiple modules inside same file).

提交回复
热议问题