Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript messy code in large projects with jquery etc?

Calling the javascript gurus out there. Basically my question is regarding how you structure your code, both visually and for functionality for example do you wrap everything in objects using this structure:

var myapp={
  binds:function(){
    //put some event listeners for jquery etc...
  },
  otherfunc:function(){
   //do some other thing
  },
  init:function(){
   //call myapp.binds and other functions and other stuff to intialize your app.
  }
};

Then finally

$(document).ready(myapp.init);

The thing is with a structure like this I think JSLint complains doesn't it? Whats the pros and cons using a structure like this or is there a generally better way to structure your code? Do you follow a certain pattern from $(document).ready(call) to putting all your event listeners and "initializing" your app, do you use separate objects for methods and variables?

I also think "visually" if you have a very large webapp this structure eventually looks very messy, but maybe it's just me I don't know, any input is appreciated thanks.

like image 989
quiggle Avatar asked Sep 27 '10 14:09

quiggle


People also ask

Is JavaScript messy?

The syntax can feel messy if you're trying to do things in a synchronous way, which is how almost all other programming languages guide you to breaking apart problems. Once you get familiar with the syntax of JavaScript and you get good at thinking about things in that way, JavaScript will feel much more natural.

Which is the most common JavaScript programming error?

Without strict mode, assigning a value to an undeclared variable automatically creates a global variable with that name. This is one of the most common JavaScript errors.

What is the problem with JavaScript?

These days, most cross-browser JavaScript problems are seen: When poor-quality browser-sniffing code, feature-detection code, and vendor prefix usage block browsers from running code they could otherwise use just fine. When developers make use of new/nascent JavaScript features, modern Web APIs, etc.)

Does JQuery make coding easier?

jQuery is a lightweight, “write less, do more”, JavaScript library. The purpose of jQuery is to make it much easier to use JavaScript on your website. jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish and wraps them into methods that you can call with a single line of code.


1 Answers

Using Inheritance Patterns to Organize Large jQuery Applications

explain in detail and with better practice by Alex

http://alexsexton.com/?p=51

its very very well explain, must see

other links

  • How To Manage Large jQuery Apps 5 months ago
like image 107
Pramendra Gupta Avatar answered Sep 21 '22 00:09

Pramendra Gupta