conventions - Is there an good reason to prefix all JavaScript modules with '$'? -


in project landed on plate, client code enclosed in revealing modules. good. of module names prefixed '$' character, e.g.

$.acme.global.dataaccess = function () {     var dataaccess = {}; 

none of these modules seems intended jquery plugin, can imagine no reason @ all, yet of code architected , written, might missing fundamental.

imo no. it's convenient, sure, because it's easy type.

for project, continue using maintain consistency. but...

the problem feel there association between '$' , jquery, confusion -- such -- bound arise. , when jquery in use, you're slapping of "acme" stuff onto "jquery" object; there's no reason unless has jquery. you'd fine creating new namespace. why not acme.global.dataaccess? it's shorter, , there no immediate confusion of whether module deals jquery or not.

tldr

  • no, no particularly reason use it
  • it can confusing
  • it tack code onto "jquery" object
  • yes, can use and..
  • for consistency, should continue using project
  • it's matter of preference really, arguably bad idea

edit:

tldr ii

cons

  • no distinct advantage
  • can mistaken inexperienced being:
    • jquery dependent, or
    • a jquery plugin
  • bad organization practices - slaps code onto "jquery" object
    • like bundling unmatched socks
  • although it's legal, it's arguably bad idea

pros

  • perfectly valid, , used before jquery
  • short , typed
  • makes feel hip, ke$ha

please add list if you've got suggestions, or troll me if disagree


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -