background preloader

Build Library

Facebook Twitter

jQuery source viewer. JavaScript Array Loops. 1) JavaScript with Native Objects, Volume III of the five-volume Frontend Engineering series, or a good grounding in basic JavaScript.

JavaScript Array Loops

In JavaScript, an array is an object, commonly having property names (strings) that look like small, non-negative integer subscripts. Arrays are constructed using array literals or by calling the Array() constructor: var array0 = []; var array1 = ['cat', 'dog', 'mouse']; // not recommended: var array2 = new Array(); // not recommended, creates ghosts: var array3 = new Array(10); For the remainder of this page we use the word "object" as shorthand for "objects that are not arrays. " JavaScript, born 1995, features two distinct loop types.

The second type, an enumerated loop, is JavaScript-specific; variants are common in other languages of the late 20th century: This leads to the question: is it appropriate to use the enumerated loop (the for/in loop) on arrays? The Conventional Wisdom Well, make that beginners and me, too. Callback Hell. Introduction to Map and Reduce in Javascript. Recently I held a short lecture on the use of functions in Javascript, and how it’s possible to use functionality like map, reduce, filter and Javascript’s amazing variable context.

Introduction to Map and Reduce in Javascript

I prefer to use underscore.js so that I can use the wonderful functionality even on old browsers. Lets start easy with _.map. Map is easy, what it does is take an input array, send each element into a function, and putting the result in a result array. The resulting array contains mapped versions of each element in the input array. Searching with Array.prototype.some. Iterating over an array to search for an item is a pretty common task.

Searching with Array.prototype.some

With JavaScript, Array.prototype.forEach is often the popular choice. In some cases however, Array.prototype.some can be a better fit for the job if there is no need to search the entire array once a condition is fulfilled. There are at least three different ways to iterate over arrays and objects in JavaScript: for loops, array methods, listing property keys. If the iteration is being carried out to perform a search operation, it may lead to the following example: Without any guards and error checks, the code above is rather self-explanatory. Let us review what the specification says about Array.prototype.forEach (Section 15.4.4.18): callbackfn should be a function that accepts three arguments. forEach calls callbackfn once for each element present in the array, in ascending order. An improvement to the search would be to stop right away once the condition is fulfilled. JavaScript Callbacks are Pretty Okay - Andrew Kelley. I've seen a fair amount of callback bashing on Hacker News recently.

JavaScript Callbacks are Pretty Okay - Andrew Kelley

Among the many proposed solutions, one of them strikes me as particularly clean: "asynchronous wait" or "wait and defer". iced-coffee-script had this a while ago. Kal just debuted with an identical solution, only differing in syntax. Best of Fluent 2012: Maintainable JavaScript.

JS Patterns

Scalable JavaScript Application Architecture. How To Create Your Own Chrome Extensions. I really like the Chrome browser.

How To Create Your Own Chrome Extensions

It wasn't until recently that I looked into creating extensions and was surprised by how simple it was. If you know basic HTML, CSS, JavaScript then you know all you need to be able to extend your Chrome browser in multitudes of ways. I decided to write up a simple guide explaining some of the basic ways you can easily extend Chrome. This is going to be a quick crash course to give you a general idea of what all you can easily do with Chrome extensions. Please let me know if you find any errors in the following. Getting Started With Extensions. Memory leak patterns in JavaScript. JavaScript is a powerful scripting language used to add dynamic content to Web pages.

Memory leak patterns in JavaScript

It is especially beneficial for everyday tasks such as password validation and creating dynamic menu components. While JavaScript is easy to learn and write, it is prone to memory leaks in certain browsers. In this introductory article we explain what causes memory leaks in JavaScript, demonstrate some of the common memory leak patterns to watch out for, and show you how to work around them. A Programmer's Ride: How to properly write JavaScript libraries. I've seen JavaScript code written in all the possible ways.

A Programmer's Ride: How to properly write JavaScript libraries

The reason there are so many ways to do it is because JavaScript is incredibly flexible. But that flexibility makes people write really ugly code. Examples of ugly, unreadable, error-prone code: (function(window, undefined) { var myLibrary = (function () { var someProp = " Your JavaScript Library. Google Closure: How not to write JavaScript. At the Edge of the Web conference in Perth last week I got to catch up with Dmitry Baranovskiy, the creator of the Raphaël and gRaphaël JavaScript libraries.

Google Closure: How not to write JavaScript

Perhaps the most important thing these libraries do is make sophisticated vector graphics possible in Internet Explorer, where JavaScript performance is relatively poor. Dmitry, therefore, has little patience for poorly-written JavaScript like the code he found in Google’s just-released Closure Library. Having delivered a talk on how to write your own JavaScript library (detailed notes) at the conference, Dmitry shared his thoughts on the new library over breakfast the next morning. “Just what the world needs—another sucky JavaScript library,” he said. When I asked him what made it ‘sucky’, he elaborated. For the rest of the day, to anyone who would listen, Dmitry cited example after example of the terrible code he had found when he went digging through Closure. Dmitry Baranovskiy's talk on Your JavaScript Library. There are my notes from Dmitry Baranovkiy’s session called Your JavaScript Library.

Dmitry Baranovskiy's talk on Your JavaScript Library

Dmitry is a JavaScript developer at Atlassian, creator of Raphaël and gRaphaël JavaScript libraries. You can see the slides on slideshare. Introduction Unlike the server-side, you don’t have a choice on client-end development: you pretty much must use JavaScript. At Atlassian, they’ve got a number of products and have abstracted their own JavaScript library out of those code bases. Why should I write a library of my own? Everyone has snippets of JS they use on every project (trim, $=getElementById). A JavaScript Library Template - Jeremy Kahn's Dev Blog. I really like to write JavaScript libraries.

A JavaScript Library Template - Jeremy Kahn's Dev Blog

This is because low-level programming interests me a lot. Although JavaScript is an inherently high-level language, I find writing the abstractions that “just work” like magic for others to be really fascinating. I’ve written a number of libraries of varying complexity, and I’ve developed a pretty good pattern that gives me a lot of flexibility when developing them. Building a library to scale is a much different challenge than building an application to scale, and it’s not discussed very much.

Libraries versus apps End users are the audience for applications. ‪write JavaScript library‬ - -Google. Creating your own JavaScript Library. One of the phases I went through while learning about JavaScript was the intense desire to write my own library, similar to jQuery (but massively scaled down). My library has gone through several major revisions — and more than one complete re-write, but now is exactly what I started out hoping it would be: functional, clean, small, and a solid learning experience. I’d like to share what I learned from this project, and I hope you share back with me through the comments!

Finished project demo Step 1: Identify the purpose of your library This might just be one of the toughest parts of the whole process! Pick one particular function, or aspect of web development/design that you would like your library to handle. Build Your First JavaScript Library. Ever marvelled at the magic of Mootools? Ever wondered how Dojo does it? Ever been curious about jQuery's gymnastics? In this tutorial, we’re going to sneak behind the scenes and try our hand at building a super-simple version of your favorite library. Toward Modern Web Apps with ECMAScript 6. ECMAScript, the official name for the language we all know as JavaScript, has enjoyed tremendous success over the last couple of years. With convergent standard support, performance boosts from modern JavaScript engines, as well as its foray into the server-side stack, ECMAScript has gained significant traction and redefined the scope of HTML5 applications.

The final requirement for world domination is the modernization of its syntax and run-time, which is coming in ECMAScript 6 and is the subject of this post. To understand the language progress within ECMAScript 6, first we need to understand how it is developed. The official ECMAScript specification, also known as ECMA-262, is defined by a standard body called Ecma International. The TC39 group within ECMA is responsible for formalizing the language specification (TC stands for Technical Committee).

The ECMAScript 6 specification is still in the draft stage. “I Can See Clearly Now” The use of the second argument, y, can be confusing.