Category Archives: javascript

Emmet as a Template (aka zen-coding)

This is not the most useful thing in the world - was just an idea I had awhile back… First off, I love Emmet (formerly zen-coding) created by Sergey Chikuyonok. I especially like it for quickly writing html or jsx.

While I don’t use them that often, I really enjoy Jade and Pug. Anyway, I realized you could do similar things with Emmet with just a few little tweaks… So created this codepen:

As you can see - with a few regular expressions you can use Emmet _sort of_ like Jade. Definitely just an experiment, but interesting nevertheless.

Also posted in html5 | Tagged , , | Leave a comment

Dynamic Getter

Getters in ES6 are usually defined within a class like this:

1
2
3
4
5
6
7
8
  class RandomPoint {
    get x() {
      return Math.random();
    }
    get y() {
      return Math.random();
    }
  }

In this case we use getters to make a random point:

  let pnt = new RandomPoint();
  console.log(pnt.x, pnt.y);
  // outputs something like 0.09403673512366306 0.2717692041118973

I found myself wanting to be able to dynamically define a getter. This can be done like this:

let rand = function() { return Math.random(); };
Object.defineProperties(someObj, { ['x']: { get: rand });

This is really all just sugar, but still fun stuff…

Also posted in Uncategorized | Tagged , | Leave a comment

HTML5 Canvas Tutorial

If you haven’t tried the html5 canvas tag yet, I suggest you give it a try. It falls under the same category as ActionScript’s Graphics and BitmapData classes. It is however much much simpler. One great thing about it is it runs really fast on IOS5. Have a look at some of these demos to see what I mean: http://zreference.com/projects/graphics/

A few days ago I recorded this short video tutorial… it’s very simple, but it will get you started if you’ve never tried canvas before:

Also posted in html5 | Tagged , , , , | 2 Comments