background preloader

The Essentials of Writing High Quality JavaScript

The Essentials of Writing High Quality JavaScript
Twice a month, we revisit some of our readers’ favorite posts from throughout the history of Nettuts+. This tutorial was first published in October, 2010. The brilliant Stoyan Stefanov, in promotion of his book, "JavaScript Patterns," was kind enough to contribute an excerpt of the book for our readers, which details the essentials of writing high quality JavaScript, such as avoiding globals, using single var declarations, pre-caching length in loops, following coding conventions, and more. This excerpt also includes some habits not necessarily related to the code itself, but more about the overall code creation process, including writing API documentation, conducting peer reviews, and running JSLint. Software bugs are costly to fix. Time to relearn and understand the problem Time to understand the code that is supposed to solve the problem Another fact of life related to software development in general is that usually more time is spent reading code than writing it.

10 Tips for Writing JavaScript without jQuery Danny Markov jQuery is a great library. It came to be around the time when IE6 was the number one browser. Back then, there were quirks and differences that were tedious to work around and jQuery was the perfect tool for writing cross browser code. Today, however, web browsers have advanced a great deal from those days. Don’t get me wrong – jQuery is still a wonderful library and most often than not you will be better off using it. 1. The first thing you do when writing jQuery, is wrapping your code in a $(document).ready() call, so that you know when the DOM is ready for manipulation. // Add an event listener of DOMContentLoaded to the whole document and call an anonymous function. // You can then wrap your code in that function's brackets // and it will execute once loading is complete. document.addEventListener('DOMContentLoaded', function () { // Our hawaiian greeting is displayed as soon as the page loads, console.log('Aloha'); }); Run 2. 3. 4. 5. 6. 7. 8. 9. Conclusion Learn more

AngularJS Form Validation Introduction Today we’ll be looking at the ways that Angular helps us do form validations. Note: We have updated this article for Angular 1.3 and the new ng-touched feature. We’ll focus on client-side validation and using the built-in Angular form properties. Demo See the Pen AngularJS Form Validation by Chris Sevilleja (@sevilayha) on CodePen Requirements Name is requiredUsername is not required, minimum length 3, maximum length 8Email is not required but has to be a valid emailForm submit is disabled if the form isn’t validShow a required or invalid email errorAlert awesome if submitted correctly Now that we know what we want, let’s get to building. Angular Form Properties $valid, $invalid, $pristine, $dirty Angular provides properties on forms that help us validate them. Angular also provides classes on the form and its inputs so that you can style each state accordingly. Accessing Angular Form Properties To access the form: <form name>. Setting Up Our Form We will need 2 files: index.html app.js

AngularUI for AngularJS Free Computer, Programming, Mathematics, Technical Books, Lecture Notes and Tutorials

Related: