What's the best way to manage Javascript code [closed] - javascript

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I'm writing a new web application, I haven't got problem with backend part (it's my job until 6years) but i'm little new with frontend development (around 1 year). What's the best way to manage your JS code?
At this time I use a single file (app.js) where i call many function like this:
writer.init();
other.init();
writer and other are functions like this
function () {
var writer = {
"init": function() {
// do something
}
}
}()
I think it's an ugly way. What are the best practices?

I'd recommend using a JavaScript framework that enforces some structure, like using directives with AngularjS. If you want to do it all yourself, this chapter of Eloquent JavaScript is a good read.

The Asynchronous Module Definition (AMD) provides a very nice way of organizing code in modules. It is especially aimed for client-side Javascript code. There are various implementations but I would recommend having a look at RequireJS.

Related

Which design pattern to learn first for javascript/jquery? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I want to learn a pattern / process for making and organising proper javascript applications. I am beginning to use OOP to simplify sections of my code, but the code is still messy so I need a process to build bigger things effectively. Should I be thinking about MVC, namespaces or libraries? Not sure if I want to choose a framework yet but any advice/suggestions is greatly appreciated!
jQuery is the best Javascript framework and you can start looking on it following the official website.
Following this blog you can find many tutorials and lessons as well.
Then if you are interested in MVC pattern to use with Javascript I suggest Backbone.
Here is all you need :
http://dochub.io/#javascript/
http://dochub.io/#jquery/
the basic knowledge of JavaScript is good to learn jquery
since the jquery is the library made in JavaScript you can manipulate and understand jquery better

AngularJS or Backbone for beginner [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm choosing a javascript framework for my Chrome extension programming (localStorage, lots of ajax calls, filtering, json manipulation). Do you recommend AngularJS or Backbone? I started with JS a few months ago (I have PHP and Java background) and the main problem for me is to have a good and clean structure of my web app.
What I like about AngularJS? The two way binding and the concept itself.
What I like about Backbone? It's really simple for beginner. And there are a lot of resources.
Full disclosure: I work on AngularJS, and obviously have a bit of a bias. ;)
If you're looking for an opinionated application structure, I would definitely stick with AngularJS. Backbone provides many helpful utilities, but there are many choices that you have to make about how you want to connect things. From my experience writing medium/large apps with Backbone.js, I've found that I have to put in more effort to keep things organized compared to AngularJS, which has much clearer separation of concerns.
The best choice is to code little projects in these two libraries.
Why not test and see the code from Todo MVC project from Addy Osmani and after that, make your choice ?

What to use to refactor the javascript / jQuery of a web application to use require.js and jasmine [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I hope this question is not too general, but i haven't found any good tutorial on how to do the transition from standard javascript / jQuery code to modular / tested code.
Mmy new task is the complete refactoring of the javascript of our wordpress plugin.
Our current code is standard jQuery code, thrown all into a file, with checks on the existance of dom elements to understand on what page we are in and attach the correct event handlers.
My goal is simply to write more manteinable and clear code, and introduce tests in the process.
My approach would be:
Try to modularize code in separate files (one file for each page) and use require.js to load only the required code.
write some tests with jasmine/sinon and try to adapt the esisting code so that the tests pass
Have you got any other suggestions/best practice?
Can you share some example on how you approached similar tasks?
I was thinking about bringing in an mvc framework but if i can stick to standard jQuery code i think it's easier for the development team because it doesn't add complexity

jQuery is JS library. what the term library means? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
i don't understand the meaning of the word library -
regarding to jQuery: will it be right to say that "library" is a huge file with many plug ins that are ready to use?
jQuery is a fast and concise JavaScript Library that simplifies HTML
document traversing, event handling, animating, and Ajax interactions
for rapid web development. jQuery is designed to change the way that
you write JavaScript.
All this means is that jQuery itself does not do anything. A library is "a collection of resources used to develop software". jQuery allows you to write cross-browser JavaScript a heck of a lot easier than it would be without it.
A library is something that extends a base langage. So in this definition jQuery is a library
A small(not huge!!!) file (32K only)... With many many functions and features.
Libraries contain code and data that provide services to independent programs. This encourages the sharing and changing of code and data in a modular fashion, and eases the distribution of the code and data.
Wikipedia

How to create a web crawler with Node.js? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I just recently got interested in how search engines work, and I found out that they use "bots" or "webcrawlers". I immediately started wondering about how do these things work and I wanted to create one! So, first of: how do you make a program that requests a page from a server? It would be awesome if you gave me a simple example in JavaScript (I'm running it as a normal scripting language using Node). Next, is there a Node module that let's me interpret HTML? Create a DOM for me so I can cycle trough all the links and so on? Correct me if I'm wrong but I guess it's done like that... Any examples in C++, C or Python are warmly welcomed as well, although I'd prefer JS or Python because I'm more familiar with high-level scripting languages.
Getting HTTP pages: node http.get (example is there)
DOM documents: jsdom (also includes examples)

Categories