展开

一分钟快速上手

FengJS是一个原创的javascript轻量级异步框架。它具备模块化、高扩展性、组件齐全,接口一致、自主开发、适合多种应用场景等特性。

FengJS配合 Angular.JS,Vue.js 等流行MVW框架,可以轻松实现template、controller的动态加载。

1.引入fengs.js文件

<script type="text/javascript" src="/js/fengs.3.0.js" ></script>

2.配置框架

Fengs.config({
	'name': 'js',							//项目名称
	'path': '/',
	'remote': {
		'js': ['/static/']
	},
	'locals': [],
	'tag': '082215',
	'lib': ['jQuery', 'Vue'],
	'depend': ['q', 'moment', 'highlight']
}).fail(function(result) {
	//加载失败回调
});

3.注册模块

//直接注册模块
Fengs.add('modulename', function(){
	return 'aaa';
});
//引用依赖模块注册
Fengs.add('othermodule', function(S, $, m){
	console.log(S);//Fengs对象本身
	console.log($);//jQuery对象
	console.log(m);//aaa, 后面引用的modulename模块对象
}, ['modulename'])

4.运行模块

//1.引用运行
Fengs.use('modulename', function(m){
	console.log(m);	//引用的模块对象
});
//2.匿名运行, 省去了先add注册再use运行的步骤
Fengs.use(function(S, $, m){
	console.log(S);//Fengs对象本身
	console.log($);//jQuery对象
	console.log(m);//aaa, 后面引用的modulename模块对象
}, ['modulename']);