Posts

Showing posts from June, 2013

Iterators and generators in ECMAScript 6

[2015-02-26] New version of this blog post: “ Iterables and iterators in ECMAScript 6 ” The iterator pattern enables unified and simple access to the elements stored in data structures. Generators are lightweight coroutines . Think: functions that can be suspended and resumed. Among other things, they help with implementing iterators. This blog post explains how iterators and generators work in ECMAScript 6. The iterator protocol has recently changed, this post explains the new protocol. Iterators In the iterator pattern, the iterator is an object that functions as a “pointer” into a data structure. It produces a sequence with all of the data structure’s elements. The pattern has two advantages: First, you don’t need an intermediate data structure for storing the sequence of elements. Thus, it is reminiscent of explicit lazy programming and allows you to work with large (e.g. disk-based) data structures. Second, many algorithms (map, filter, etc.) can based on iterators and are dec

Mary and Lou and Rhoda and Ted

Image
Arguably, television is culture.   And I’ll add, television, good and bad, reflects culture.   We turn on the tube to feed our obsession with cop shows and law enforcement, terrorism and shadow governments, health care and the drama of the emergency room, and of course, our voyeuristic need to look in someone’s window and observe “reality,” which in reality, is often not even close.   But the glass tube has been cracked open; cable channels own the monopoly on the most interesting work being done in T.V. land right now while networks keep commissioning false reality and scripted fare in the vain hope that the lonely hearts on the other end of the digital signal will find romance with The Bachelor or take the stage as the next American Idol .   Meanwhile, viewers have moved on to computer screens and tablet pixels, and the old school Nielsen ratings are ancient history.   We DVR our shows now and watch them wherever and whenever we like, and some of the best are not on television at al

Searching websites and evaluating JavaScript via Chrome’s omnibox

Image
This blog post explains how to search several websites (not just a single search engine!) from the omnibox (address bar) in Google Chrome. Managing search engines The default is simple: If you enter something in the omnibox and hit return, Chrome uses your input as a search query for Google. Via “Settings → Search”, you have the option of choosing a different search engine for this operation (my Chrome has the defaults Google, Yahoo, Bing). Next to the drop-down list with the defaults, there is the button “Manage search engines...”, which is where things get interesting. First there is a list with “default search engines” (the ones in the drop-down list), then there is a list with “other search engines”. You can add new search engines to the latter and then move them to the former by clicking the “Make default” button that appears when you hover over an appropriate item. A search engine entry has three fields: A name, a keyword and a URL. The keyword is an abbreviation for the URL, the

Basic JavaScript for the impatient programmer

Update: This blog post has become a chapter in my book “ Speaking JavaScript ”. You can read it here: “ Basic JavaScript ”. Kind words by Cody Lindley (author of “ jQuery Enlightenment ”, “ JavaScript Enlightenment ” and “ DOM Enlightenment ”): “Basic JavaScript” … [is the] most complete and concise write up I am aware of. This blog post enables you to get started with JavaScript as quickly as possible – if you already know how to program. It describes the smallest subset of the language that allows you to be productive. I call that subset “Basic JavaScript” and recommend to program in it for a while, before moving on to more details and advanced topics. Learning everything at once is too confusing. The post concludes with tips for what to learn next . Warning: Below, I’m describing rules of thumbs and best practices. I favor clarity over precision (e.g., whenever you see the word “roughly”). The rules are safe, but – unavoidably – a matter of taste. Table of contents 1. Convent