基本框架设计--以JsonFormater为例,思考设计
1.对象创建
//define prototype function
function JsonFormater(opt){
}
//define prototype
JsonFormater.prototype={
}
调用:
下面为小例子:
调用脚本:
<script type="text/javascript">
$(document).ready(function () {
var jf;
jf = new Student("hh");
jf.hello();
});
</script>
1.对象属性
(1).对外参数写法
this.options=$.extend({
xx:'',
tabSize:2
},opt||{});)
借助extend实现
$.extend(a,b)
(2).Jquery扩展说明
1.jQuery.extend(object);为扩展jQuery类本身.为类添加新的方法。
2.jQuery.fn.extend(object);给jQuery对象添加方法。
(3)注意填充对象和属性方法
code
function JsonFormater(opt){
//out modify
this.opt=$.extend({
dom:'',
tabSize:2,
singleTab:"",
quoteKeys:true,
imgCollasped:"/image/Collasped.gif",
imgExpanded: "/image/Expanded.gif",
isCollapsible: true
},opt||{});
this.isFormated=false;
this.obj={
_dataObj:new Date(),
_regexpObj:new RegExp()
};
this.init();//function must the method is regexp
}
//define object 实例方法
JsonFormater.prototype={
//append init function
init:function(){
}
}
调用: