For example if you write a plugin you could do this $('#myDiv').doAction() instead of doAction($('#myDiv')). and you have to admit, the first one looks more intuitive. Are there any clear drawbacks of this like performance hits?
For example if you write a plugin you could do this $(‘#myDiv’).doAction() instead of
Share
You won’t see any noticeable performance hit from this, but there is one potential drawback: namespacing your code is very valuable, and makes it easier to maintain (as you probably know). Throwing everything into
jQuery.fnmay not be the best way to do this.Personally, I shy away from extending jQuery with very specific things (like app-specific logic or something) but whole-heartedly recommend it for general, DOM-level things (
.hasAttr()and.scrollHeight()are two I use a lot). The reason is that there are better places to put app-specific logic (in the module in charge of that area of the app, for example).A simple heuristic: would it be useful to other people if I made this a public extension? Or is this only relevant to this particular project?
That said, there is no concrete problem with doing this in your code. It’s more a semantic issue: is that the best place for it?