.Jquery插件开发(02)--插件设计

基本框架设计--以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(){

}

}

调用:

插件开发基础:Jquery插件开发(01)

下一篇:Jquery插件开发--核心功能篇

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值