Posts

Showing posts from February, 2013

ECMAScript 6’s parameter destructuring and forEach()

This blog post gives a brief introduction to destructuring in ECMAScript 6 and how the array method forEach() profits from it. Destructuring ECMAScript 6 allows you to destructure : the target of an assigment can be a pattern that allows you to look into the source of the assignment and assign to variables what you find there. The following is an example of destructuring used in a variable declaration: > let { first: f, last: l } = { first: 'Jane', last: 'Doe' }; > f 'Jane' > l 'Doe' Another example: you can swap the values of two variables x and y like this: [x,y] = [y,x]; Destructuring also works for parameters. The following function has two kinds of parameters: the first parameter is positional (identified by position), the remaining parameters are named (identified by name) and wrapped in a so-called options object (which is actually a second positional parameter). function foo(positional, { named1, named2 ...

Carl Jung

Image
I have been drawn to Carl Jung for years because of his work with dream analysis, archetypes, literature, and philosophy.   In the last year of studying religions of the world, he has become even more valuable.   So, when I was browsing one of my favorite bookstores up in the Santa Barbara region of California, Chaucer’s Books , I stumbled across a recent publication of Jung’s The Red Book (Liber Novus):  A Reader’s Edition (Norton, 2009).   However, I had no sooner come home on that rainy evening and curled up on my couch than I found I needed some more background reading of Jung to fully understand the placement of The Red Book within the Jungian bibliography.   Specifically, I had used Jung’s work as background to my studying and teaching of literature.   For a few years now, I have had his autobiography, Memories, Dreams, Reflections (the Vintage Books edition of 1965) sitting on my shelf.   I had not read it through in its entirety, so I figured...

Perl and Python influences in JavaScript

If you search the Mozilla Central code base for the texts "Perl" and "Python" (don’t ignore case) then the comments mention what methods have been borrowed from those languages. The paths mentioned below are relative to /js/src/ . [Inspiration: a blog post by Ziyun Fei.] Perl influences in ECMAScript 5 String ( jsstr.cpp ): String.prototype.match() String.prototype.replace() String.prototype.split() String.prototype.substr() Array ( jsarray.cpp ): Array.prototype.join() Array.prototype.reverse() Array.prototype.sort() Array.prototype.push() Array.prototype.pop() Array.prototype.shift() Array.prototype.unshift() Array.prototype.splice() RegExp ( builtin/RegExp.cpp ): generally Perl-inspired, one comment attests to that fact. Python influences in ECMAScript 5 String ( jsstr.cpp ): String.prototype.concat() String.prototype.slice() String.prototype.match() Array ( jsarray.cpp ): Array.prototype.co...

Teacher Fails

Image
Rembrandt Peale (1778-1860) Working Sketch of the Mastodon Sam was a skateboard aficionado in my seventh grade literature class.   He wore his blue uniform shorts without a belt, and did not ditch his blue Vans even when they had holes and had seen better days.   Sandy brown hair and blue eyes capped him off.   He was the stereotypical San Fernando Valley teenager, but he was not apathetic nor a daydreamer.   He had a brain and was not afraid to use it. During class, Sam kept his head down, drawing furiously in a notebook.   From my position in the room, he sat front and center.   I could see figures, cartoons, speech bubbles, and ray guns.   Meanwhile, I took the class through Night and Tom Sawyer and a host of other novels. When I called on him, Sam always had a ready and correct answer.   His work was thoughtful and full of insights.   All the while, he kept drawing in his notebook.   When I thought he was lost in his art, I’d call...

Link-friendly content

Have you published a blog post or a GitHub project? This document gives tips for making your content appealing to link to. They are based on things I noticed while collecting material for the JavaScript Weekly email newsletter. The tips should also make your content more appealing to “normal” readers. Cosmetic tips A few superficial measures for a better first impression: Spelling: Make sure your spelling is OK. Alas, the “.js” suffix is used in many variations. When in doubt, look up the name you are referring to. Names that are very often spelled wrong: JavaScript (not Javascript) Ajax (not AJAX): it’s not a real acronym, see the post where the term was invented Node.js or Node (not NodeJS): this one is more tricky, as there are many variations. Starting with a capital N and ending with “.js” seems the most common way to spell it. Links: Don’t use URL shorteners. They don’t let you see where they are poin...

Cemetery Weather

Image
Today is cemetery weather. Many of my family members are buried in the San Fernando Mission Cemetery at the north end of the valley.   On days like today, we leave mass and travel a few miles up the 405 to visit graves and say a few prayers in memory of loved ones long and recently departed.   My mother is buried there, right next to my paternal grandparents.   About fifty yards away are my mother’s parents, side-by-side as well, even though my grandmother lived on to marry my second grandfather, who was cremated and scattered at sea. Vibrant blue skies and a fresh breeze always seem to accompany our time in the cemetery.   The grass is green from winter rains.   I smell the earth and trees.   We clean the grave markers, carefully cutting away the shoots of St. Augustine grass that have encroached on the margins of stone.   I fill the iron vases with water so we can place new cut flowers.   Once the grave is clean and the flowers in place, we kn...