- Most Recent | Since 2004
- List View
- Archive
- February 13, 2013
HTML5 Crash Course: Digging into Javascript’s Weirdness
February 13, 2013Read more[snip-h5cc]
Today I looked at the HTML5 Boilerplate and KnockoutJS.
- HTML5 Boilerplate is an application framework, meaning it’s a bare-bones way of structuring the way your HTML5 app loads resources and starts up. The alternative is to come up with your own organization.
KnockoutJS is a pure Javascript library that implements a “Model – View – ViewModel” pattern in a clean, declarative way. I don’t yet know exactly what the ramifications are, but there’s an awesome interactive tutorial that walks you through it.
<
p>Exploring these two environments today gave me additional insight into Javascript Weirdness related to its super-flexible object-oriented underpinnings. Basically everything is an object, even the ones that look like they might be functions or expressions. Writing Javascript is like living on the frontier, where STREET JUSTICE prevails over centralized language specification. There are no police. It’s up to you to enforce good programming habits, because Javascript doesn’t have any built-in to save you from shooting yourself in the foot.
As a result, you need to explore the Javascript community for a bit to understand what the law of the land is. Here’s some of the ones that I collected yesterday:
Functions and Parenthesis
The jQuery library is used everywhere, as it is one of those libraries that makes cross-browser DOM manipulation more “write-once” than “hope and pray it works in every browser”, which was the reason I avoided Javascript for so many years. To start executing your code that uses jQuery, though, you need to make sure it’s loaded. Since browsers load resources asynchronously, and also have slightly different ways they do it, jQuery itself provides a means to call your important startup function:
$(document).ready(). Theready()call takes a function as an argument, which is executed when it’s time to run.Unfortunately, in the non-trivial code examples, the ready() sometimes looks like this:
(function($) { $(function() { // code using $ as alias to jQuery }); })(jQuery);Note the enclosing parenthesis. WHAT IS THIS? The short answer is that it converts the function() definition into an object expression which is then executed immediately, with the jQuery object passed to it as a parameter. WHY IN THE WORLD would you want to do something as convoluted as this? It’s to make the variables in your code private through the implicit creation of a Javascript “Closure”, which is the variable scope/state within a function. Since scripts in a browser all run in the same global namespace, they can overwrite each other. The code here creates an anonymous function, which in turn has its own closure with the $ variable assigned to the jQuery object. Everything inside has its own private space to declare whatever variables it wishes. Furthermore, the variable state exists after the code finishes running (another aspect of closures which is a bit different from other compiled languages), so you can safely assign event handler functions that refer to variables inside; they remain persistent.
The enclosing parenthesis is not necessary, but is added so you can tell right away that this is the case. Technically, Javascript will do the closure thing because of the
(jQuery)tacked on the end, but it is unclear that it’s not a function definition until the very end. Adding the explicit () around it turns it into an explicit EXPRESSION instead of a function declaration; this is pure coding style because the () at the end also turns the function declaration syntax into an expression, but you see it all the way at the end and then you’re like, “damn, this isn’t a definition that’s called, it’s something that runs right now”.You also see stuff like:
!function($) { $(function() { // code using $ as alias to jQuery }); }(jQuery);I KNOW…WHAT? The ! is the unary negation operator, and it has the side effect of telling Javascript that an expression follows it. This is the same effect as using (), which is the arithmetic precedence operator. Both, being operators, turn the function into an expression, which is OK because expressions can be executed when a () is after them to turn it into a function invocation. That executes immediately. You could also use + or – as well and get the same effects…it’s purely for code readability.
It seems stupid, but it’s necessary to establish a private namespace (via closures) so you can write code without side effects like name collisions. Other languages have explicit ways of establishing a namespace, but Javascript does not.
Well, there is stuff like this:
var myNameSpace = myNameSpace || {} myNameSpace.myProperty = 1; myNameSpace.myFunction = function(x) {};This creates an object with objects assigned on-the-fly. Although since I used
var, it’s local to the closure that the namespace is declared in. If I didn’t usevar, I think that means it would be in the global namespace. Argh.Anyway, that is enough of this for the day. Here’s the links that helped me understand this:
- http://michaux.ca/articles/an-important-pair-of-parens
- http://blog.themeforest.net/tutorials/ask-jw-decoding-self-invoking-anonymous-functions/
- http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth
- February 12, 2013
Feb 14: Dave Live on “Lean Into Art” Podcast
February 12, 2013Read moreThe boys of the Lean into Art video podcast, Jerzy Drozd and Rob Stenzinger, have invited me onto their show! They cover a variety of topics dear to my heart: entrepreneurial creativity, digital media, illustration, animation, video game design and development, and of course productivity tools. They’ve set up the event as a Google Hangout at 9PM EST Feb 14, which will have a chatroom accompanying the live streaming (?) event. Exciting! A great way to spend International Quirky-Alone Day <3
- February 12, 2013
“The Personal MBA” Free Course on Creative Live!
February 12, 2013Read moreJosh Kaufman, author of The Personal MBA, is doing a course on CreativeLIVE starting this Thursday at 12PM ET (9AM PT). The topic: Fundamentals of business! The Personal MBA is Josh’s distillation of dozens and dozens of business concepts, organized to make the utility and relationship between then as clear and actionable as possible…it’s really quite remarkable, and is one of my favorite business books ever.
- February 12, 2013
HTML5 Crash Course: Some Starting Specification
February 12, 2013Read more[snip-h5cc]
Yesterday I’d started to gather materials on HTML5 online before remembering that I had a book. I septn a little bit of time before going to sleep skimming the HTML5 and Javascript references I have, and came to the conclusion that HTML5 itself is just a bunch of new features. The ones I’m interested in are the Canvas, Sound, and Event models.
I need a very basic app to get focused. It might be instructive to write a simple GUI that gets something done. That would familiarize myself with a few things
- Basic HTML5 Layout of Elements
- Using jQuery to bind events to the Elements
- Writing some Javascript core code to send events and data requests to my own server using JSON or something
I think I’d like to make a basic two-column text editor. This is something that’s been on my mind for a while.
I’m kind of tired, so I think I’ll do the setup of a framework later today or tomorrow. My testbed will be the davidseah.net server, where my other experiments live.
Here’s what the HTML5 page needs:
- HTML5 markup!
- A place to LOAD script libraries!
- A way to detect no javascript and gracefully degrade
- A way to debug!
That’s a good enough starting list.
- February 12, 2013
Day 12: A Cootie Catcher for Creative Self-Reliance
February 12, 2013Read more
I woke up in the middle of the night, tossing and turning fitfully. Unable to completely fall back asleep, I let my mind drift to the product of the day (POD). What what be a nice counter-balance to yesterday’s legal form? My addled mind reached back to 2006, when I had started to make an origami fortune teller AKA “cootie catcher” template filled with wisdom. I never got around to releasing it, because I couldn’t think of eight good fortunes that tied-in with the productivity forms. Eight fortunes? It so happens that I now have eight separate operating principle cards from Day 9!!!
One happy design fact about cootie catchers: all the graphics can be printed on one side! Pretty cool, right?
Folding It
Here’s what it looks like once you print, trim, and fold it.



NOTE: When trimming, make sure you cut THROUGH the color bleed along the dotted line, not around it.
Using It
The “fortune-telling” are prompts related to being creatively self-reliant. I used the principles I follow when I need to be unafraid when moving through uncertain territory. To invoke them with the cootie catcher, follow these 3 steps:
- The outside displays my 4 critical process words: EXPLORE – LEARN – BUILD – SHARE. Pick a word that appeals to you and do the open/close motion for the number of letters in the word. For example, LEARN has five letters, so do the open/close motion for 5 times.
Now, look inside and pick a number! Do the open-close motion for that amount.
You can pick whatever word grabs you the most. Lift up the flap to read your creative self-reliant reminder. Try to tie-it-back to the first word you picked, and SHAZAAM! The mystic powers of creativity wash over you!
<
The “fortunes” are based on my “creative operating principles” mentioned earlier, which I’ve been collecting over the years as I come across the ones that ring true to me. Your experience may vary; I’d love to hear about it if you’re so inclined to share.
Download
You know you want this!
» Download The Creative Cootie Catcher PDF
If you need some more help, this YouTube video shows you how to do the folds. Or for the authentic tween experience, let your new best friend “Chelsea” show you how it’s done. She’s awesome! I know, right?
Adobe Acrobat Reader is recommended for printing. The built-in "Mac OS X Preview" and "Chrome Browser" PDF viewers do not always draw dotted lines correctly.
Enjoy!
Groundhog Day Resolution Posts for 2014
I am challenging myself to create a new product every day for the month of February 2013. The Challenge Page lists all the products in one place. Check it out!
I woke up in the middle of the night, tossing and turning fitfully. Unable to completely fall back asleep, I let my mind drift to the product of the day (POD). What what be a nice counter-balance to yesterday’s legal form? My addled mind reached back to 2006, when I had started to make an 



