- ARCHIVE / Functional
- 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]);
[...] - 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 [...]
- 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 [...] - How to help your users out as a library designer
Seems my functional posts have been generating an obscene amount of traffic lately (thank you, Reg). In which spirit, here’s a little suggestion for anyone designing a JavaScript library.
I was reading about Oliver Steele’s MIT-licensed Functional library earlier, and came across this little gem (modified slightly to my whims):
/**
* Returns a function identical to [...] - Bringing “static” type-checking to JavaScript
It looks like my language to learn for this year is Java. Last year (well, tail end of 2006) is was Ruby and Rails, and I’m very much still learning as far as those are concerned. I also got heavily into JavaScript; I’d done a little jQuery before but 2007 was the year I really [...]
- Deriving the Y combinator
Before I start in on this: be aware I’m mostly writing this to force myself to understand something by writing it down. If you get anything out of it, consider it a bonus. I will be deriving Y() in JavaScrpit, and giving a version in Ruby.
After stumbling on this article on Raganwald last year (thoroughly [...] - Self-currying JavaScript functions
I’m telling you, this language keeps surprising me. You’ll need Prototype for this one.
Function.prototype.toSelfCurrying = function(n) {
n = n || this.length;
var method = this;
return function() {
if (arguments.length >= n) return method.apply(this, arguments);
return method.curry.apply(arguments.callee, arguments);
};
};
Make a simple function:
var adder = [...] - Methodize and functionize
Though the API docs seem to make no mention of it, there is this little gem sitting in Prototype 1.6.0:
Function.prototype.methodize = function() {
if (this._methodized) return this._methodized;
var __method = this;
return this._methodized = function() {
return __method.apply(null, [this].concat($A(arguments)));
};
};
What that does is it returns a new function [...]