封装jquery适配seajs模式

来源:互联网 发布:淘宝网夏季女装上衣 编辑:程序博客网 时间:2024/06/01 09:38

jquery背身对于AMD支持很好,对于cmd支持不是很好,如果使用seajs开发框架,需要注意封装jquery,以适用;

封装方法无非更改jquery源码,

在jquery源码中找到

    if ( typeof define === "function") {        define( "jquery", [], function() {            return jQuery;        });    }
然后替换为

    if ( typeof module === "object" && module && typeof module.exports === "object" ) {        module.exports = jQuery;    } else {        if ( typeof define === "function" && define ) {            define( "jquery", [], function () { return jQuery; } );        }    }    if ( typeof window === "object" && typeof window.document === "object" ) {        window.jQuery = window.$ = jQuery;    }
这样就可以了;


针对压缩后的jquery,找到

"function"==typeof define&&define.amd&&define("jquery",[],function(){return m});
然后替换为
"function"==typeof define&&define.cmd&&define("jquery",[],function(){return m});




0 0
原创粉丝点击