Which casing looks better to you for a jQuery plugin:
$("#foo").runMyPlugin();
or
$("#foo").runmyplugin();
Is there a naming convention for jQuery that prefers on over the other?
Thanks in advance!
Naming Conventions For example: Variable and function names written as camelCase. Global variables written in UPPERCASE (We don't, but it's quite common) Constants (like PI) written in UPPERCASE.
A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign " $ ", or the underscore character " _ ". The convention, however, is to always begin your variable names with a letter, not " $ " or " _ ".
A jQuery plugin is simply a new method that we use to extend jQuery's prototype object. By extending the prototype object you enable all jQuery objects to inherit any methods that you add. As established, whenever you call jQuery() you're creating a new jQuery object, with all of jQuery's methods inherited.
I would recommend you the first one, that convention is widely used in JavaScript, even in the core language by itself, the ECMA Specification uses it, e.g.
Array.prototype.toLocaleString
Object.prototype.hasOwnProperty
Object.prototype.propertyIsEnumerable
// etc...
All identifiers are named with camelCase, and only constructor functions are named with the first letter as capital (PascalCase).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With