background preloader

Basic Concepts explained in depth

Facebook Twitter

An Introduction To DOM Events. Click, touch, load, drag, change, input, error, resize — the list of possible DOM events is lengthy.

An Introduction To DOM Events

Events can be triggered on any part of a document, whether by a user’s interaction or by the browser. They don’t just start and end in one place; they flow through the document, on a life cycle of their own. This life cycle is what makes DOM events so extensible and useful. As developers, we should understand how DOM events work, so that we can harness their potential and build engaging experiences. Throughout my time as a front-end developer, I felt that I was never given a straight explanation of how DOM events work. I will introduce the basics of working with DOM events, then delve into their inner workings, explaining how we can make use of them to solve common problems. Listening For Events Link In the past, browsers have had major inconsistencies in the way they attach event listeners to DOM nodes. An Introduction To DOM Events. The Dangers of Stopping Event Propagation. Composition in Javascript - @rjzaworski. Last week offered some fairly esoteric notes on dependency injection.

Composition in Javascript - @rjzaworski

This week, it’s time to put them to use with a quick dive beneath the waters of object composition. Besides being an extremely common use-case for dependency injection techniques, composition is also a useful alternative to traditional inheritance and an extremely valuable tool for decoupling Javascript objects. Before we begin, let’s write a naive implementation of a sorted list–an object-oriented straw man, if you will, to carry through a few demonstrations. function SortedList () { this. _items = [];} SortedList.prototype.add = function (newItem) { this.

JS Comparison Table. A Dive Into Plain JavaScript. Viljami S. wrote this on While I’ve worked over a decade building various websites, it has only been the past 3 years that I’ve started learning more on how to work with plain JavaScript, instead of using jQuery always as the starting point.

A Dive Into Plain JavaScript

The fact that I’m learning a dozen new things every day now, has made working on Adtile’s JavaScript SDK feel more like building an open source project than “actual work,” and I have to say I like that a lot. Today, I’m going to share some of the basic things I’ve learned during the past years, which will hopefully also help you to dive into the world of plain JavaScript, making it easier to decide whether or not you will need jQuery in your next project.

Progressive Enhancement While libraries like jQuery help to forget most of the browser inconsistencies, you really become familiar with them once you start using plain JavaScript for everything. Here’s How We’re Doing It. Closures in JavaScript. By now, you probably know all about functions and all the fun functiony things that they do.

Closures in JavaScript

An important part of working with functions, with JavaScript, and (possibly) life in general is understanding the topic known as closures. Closures touch upon a gray area where functions and variable scope intersect: Now, I am not going to say any more about closures, for this is something best explained by seeing code. Any words I add right now to define or describe what closures are will only serve to confuse things. In the following sections, we'll start off in familiar territory and then slowly venture into hostile areas where closures can be found. Douglas Crockford on coding standards. 7 JavaScript Basics Many Developers Aren't Using (Properly) JavaScript, at its base, is a simple language that we continue to evolve with intelligent, flexible patterns.

7 JavaScript Basics Many Developers Aren't Using (Properly)

We've used those patterns in JavaScript frameworks which fuel our web applications today. Lost in JavaScript framework usage, which many new developers are thrust right into, are some of the very useful JavaScript techniques that make basic tasks possible. Here are seven of those basics: 1. String.prototype.replace: /g and /i Flags One surprise to many JavaScript newbies is that String's replace method doesn't replace all occurrences of the needle -- just the first occurrence. A Recursive setTimeout Pattern - Eric Hynds. ← all posts Monday, October 18, 2010 Colin Snover wrote a good article about why he thinks setInterval is considered harmful: setInterval ignores errors.

A Recursive setTimeout Pattern - Eric Hynds

If an error occurs in part of your code, it'll be thrown over and over again.setInterval does not care about network latency. When continuously polling a remote server for new data, the response could take longer than the interval amount, resulting in a bunch of queued up AJAX calls and an out-of-order DOM. The solution is to recursively call a named function within setTimeout, which guarantees that your logic has completed before attempting to call it again. So how to do this? I'm doing three things here: Declaring a function loopsiloop that is immediately invoked (notice the parens at the end).Declaring a timeout handler to fire after 5 seconds.Polling the server inside the timeout, which upon either success/failure will call loopsiloop and continue the poll.

It's also important to remember that DOM manipulation takes time as well. Why does console.log.apply() throw an Illegal Invocation error. What is the 'new' keyword in JavaScript.