JavaScript 加载执行器 Require

码农软件 · 软件分类 · 文件上传组件 · 2019-03-30 06:29:04

软件介绍

JavaScript 加载执行器,可用于同步或异步加载执行任何js文件。

实例:

1、引入js文件

2、配置require-config.js

require.config({
baseUrl : '.',//可写实际url(
http://xxx.com),也可不写
group : {//定义控件组
'Base' : [ 'Constant', 'DateUtil', 'ValidUtil', 'BaseUtil' ]
},
path : {//定义js文件路径不需要加js会自动加载baseUrl前缀
'Constant' : 'constants/Constant',
'DateUtil' : 'utils/DateUtil',
'ValidUtil' : 'utils/ValidUtil',
'BaseUtil' : 'utils/BaseUtil',
'JSEncrypt' : 'lib/jsencrypt',
'StatusEnum' : 'enums/StatusEnum',
'UserTypeEnum' : 'enums/UserTypeEnum'
}
});

3、使用require 需要使用的变量必须公布到window

BaseUtil.js(function(window){function private(){
}
window.init = function(){
    console.log('test');
}
   
})(window);

3.1、异步回调require.async,

/**
*@param1 array or string
*@param2 function
*/
require.async(['Base','StatusEnum'],function(){
//执行BaseUtil的方法
BaseUtil.init();
});

3.2、同步执行require.sync

/**
*@param1 array or string
*@param2 function
*/
require.sync('Base');
//执行BaseUtil的方法
BaseUtil.init();

兼容性:

Safari 6+ (Mac)

iOS 5+ Safari

Chrome 23+ (Windows, Mac, Android, iOS, Linux, Chrome OS)

Firefox 4+ (Windows, Mac, Android, Linux, Firefox OS)

Internet Explorer 8+ (Windows, Windows Phone)

Opera 10+ (Windows, linux, Android)

本文地址:https://codercto.com/soft/d/2453.html

Design for Hackers

Design for Hackers

David Kadavy / Wiley / 2011-10-18 / USD 39.99

Discover the techniques behind beautiful design?by deconstructing designs to understand them The term ?hacker? has been redefined to consist of anyone who has an insatiable curiosity as to how thin......一起来看看 《Design for Hackers》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具