TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

How to Write Superior jQuery Plugins

48 pointsby nvitasabout 13 years ago

2 comments

omgseanabout 13 years ago
When I'm writing jQuery code I like to use $varName to refer to vars which store a jQuery object, and plain old varName for everything else. This is a fairly common technique that I picked up from I think Paul Irish or Rebecca Murphey.<p>In your case of $this and this I would generally declare var self = this rather than var $this = this. Fairly often if "this" is an HTML element I'll declare var $this = $(this).<p>Not saying your way is wrong but I do find it helps me to keep my jQuerified and non jQuerified variables visibly separate.
评论 #3639891 未加载
c4urselfabout 13 years ago
I recently wrote a template for jquery plugins which uses many of the ideas in the article, it's based on the Twitter Bootstrap 2 jQuery templates:<p><a href="https://github.com/c4urself/jQuery-Plugin-Template/blob/master/jquery.plugin.template.js" rel="nofollow">https://github.com/c4urself/jQuery-Plugin-Template/blob/mast...</a>