jQuery Common Coding and Plugin development tips

jQuery Common Coding tips:
1, less code by chain coding
2, Use data method instead of storing data inside the DOM.
 $('selector').data('meaningfullname', 'this is the data I am storing');
// then later getting the data with
$('selector').data('meaningfullname');

3, If you are Manipulating the DOM a lot, use livequery.(1.3)
    $('div.edit').livequery('click', function(){
//go into edit mode
});

4, Use classes as flags:With jQuery you can add a class with the addClass method and then check later if an element has the class with the hasClass method.
5, use same function name to handle different arguments
6, pass options for configuration data
7, test your code by screw.unit
8, make most jQuery code into resuable plugins

jQuery plugin pattern tips:
(from: http://www.learningjquery.com/2007/10/a-plugin-development-pattern)
1. Claim only a single name in the jQuery namespace
2. Accept an options argument to control plugin behavior
3. Provide public access to default plugin settings
4. Provide public access to secondary functions (as applicable)
5. Keep private functions private
6. Support the Metadata Plugin
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值