您实际上可以做两件事,这取决于您是否要添加全局变量。在任何情况下,您都会创建一个modernizr.js 文件,并且如果您想创建一个全局变量
define( function() {
/* Modernizr 2.5.3 (Custom Build) | MIT & BSD
* Build: http://modernizr.com/download/#-touch-cssclasses-teststyles-prefixes-load
*/
Modernizr = (function( window, document, undefined ) {
// all your modernizr code
return Modernizr;
})(window, window.document);// Be careful to change this with window
} );// This closes the define call
那么你可以简单地
require( ['modernizr'], function() {
// Here the script has loaded and since you added a global variable, use that
if(!Modernizr.borderradius){
});
如果你不想添加一个全局变量,你应该做
define( function() {
/* Modernizr 2.5.3 (Custom Build) | MIT & BSD
* Build: http://modernizr.com/download/#-touch-cssclasses-teststyles-prefixes-load
*/
// Change the name of the variable so you don't have scope issues
var modernizr = (function( window, document, undefined ) {
// all your modernizr code
return Modernizr;
})(window, window.document);// Be careful to change this with window
// Return your variable
return modernizr;
} );// This closes the define call
接着
require( ['modernizr'], function( Mdzr ) {
// Here the script has loaded and you assigned the return value of
// the script to the variable Mdzr so use that
if(!Mdzr.borderradius){
});