- ARCHIVE / JavaScript
- Where did all my code go? Using Ojay chains to express yourself clearly
I’ve been putting together a presentation to be given internally at work on what Ojay is and why we’re doing it. It occurred to me that I’ve not spoken very much about it here, hoping the documentation and examples would speak for themselves. So, today I’m going to go through how to take an animation [...]
- Brain teaser
In response to Dustin Diaz (you’ll need a JavaScript 1.8 capable browser, or Ojay):
var arr = ['a', 'b', 'c', 'c', 'd','e', 'e',
'e', 'e', 'e', 'f', 'e', 'f', 'e',
'f', 'a', 'a', 'a', 'f', 'f', 'f'];arr.reduce(function(memo, letter) {
var last = memo[memo.length - 1];
if (!last || last[0] != letter) memo.push([letter]);
[...] - Inheritance, revisited
Late last year, I wrote a piece titled “Where’s my inheritance“, in which I argued against the inheritance implementation of various JavaScript libraries. I’ve recently been working on a rewrite of JS.Class that is much more Ruby-like, and it’s caused me to re-examine my thoughts on this issue.
With JS.Class 1.x, I made the conscious decision [...] - There is no such thing as a JavaScript plugin
One thing that you often hear people say about jQuery is that is has a neat plugin mechanism. It’s true there are a great many useful plugins available for jQuery and it makes them super-easy to write, but I want to let you in on a little secret:
jQuery.fn = jQuery.prototype;
That is jQuery’s plugin mechanism in [...] - Ojay 0.2.0: easy keyboarding, a validation DSL, and two new UI widgets
It’s been about four months since our last release (and I really did want this to happen about a month ago, but I’ve only so much time), and now we have a new version of Ojay for you to download and play around with. It’s a drop-in replacement for 0.1.x so you really have no [...]
- Dispatching YouTube API events to individual JavaScript objects
Last week, I had the enviable task of creating a skinnable version of the YouTube player using JavaScript; something that would drop some HTML into the page that could be styled using CSS. Naturally, I wanted to package it up as a reusable class so you could, if required, create several videos on a single [...]
- Anything that can be automated should be
I’ve been using a few bits of YUI’s widget library lately and am constantly surprised by the markup requirements they list in the examples. For example, if you want a text field to be autocompletable, you need to use the following markup:
<div id=”myAutoComplete”>
<input id=”myInput” type=”text”>
<div id=”myContainer”></div>
</div>
Given their [...] - A plea to IE
Please, please implement getters and setters in your JavaScript engine. I cannot tell you how much I want to add this to JS.Class:
var MagicMethods = {
included: function(klass) {var define = function(object, name) {
var shortName = name.replace(/^[gs]et[A-Z]/,
[...] - JS.Class 1.6.0: Forwardable, State, and Ruby
A little update: JS.Class 1.6.0 is now out. The main new features are a port of Ruby’s Forwardable module for method delegation, an implementation of the State pattern (which I’m using heavily for building UI code), and JS.Ruby, which is something I wrote about a few weeks back. Also, I’ve implemented the extended hook to [...]
- Automated example code displays
I’ve been writing some code examples for some of the UI components I’m writing for Ojay, and I need to display the implementation code and stylesheet on the page. Pretty standard fare: here’s a UI example, and here’s the code you need to implement it. Easy.
Trouble is, I don’t want to duplicate the code (once [...]