最佳答案
我正在使用 Requidjs + jQuery,我想知道是否有一种聪明的方法可以让 jQuery 插件与 need 一起工作。
例如我正在使用 jQuery-cookie,如果我理解正确的话,我可以创建一个名为 jQuery-cookie. js 的文件,然后在里面做
define(["jquery"], // Require jquery
function($){
// Put here the plugin code.
// No need to return anything as we are augmenting the jQuery object
});
requirejs.config( {
"shim": {
"jquery-cookie" : ["jquery"]
}
} );
我想知道我是否可以像 jQuery 那样做,就像这样:
if ( typeof define === "function" && define.amd && define.amd.jQuery ) {
define( "jquery", [], function () { return jQuery; } );
}
或者这是使 jQuery 插件与必要条件或任何 amd 兼容的唯一方法