- ARCHIVE / Metaprogramming
- 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 [...] - 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 [...]
- Quick and dirty icons in ActionView
Tiny tiny Rails tip: you can use method_missing to make using icon sets easier when writing Rails views. Behold:
module ApplicationHelperdef method_missing(sym, *args)
super unless sym.to_s =~ /_icon$/
image_tag(”silk/#{sym.to_s.gsub(/_icon$/, ”)}.png”)
endend
Now the following call:
<%= pencil_icon %>
produces this image tag:
<img src=”/images/silk/pencil.png” /> - Composing DSLs in JavaScript
Further to my previous post I thought I’d share the approach I’ve been using to compose DSLs in JavaScript. If you want a more involved example, check out the currently in-development Forms module for Ojay.
For this example I’m going to be writing a simple permissions language that sets up rules about when certain methods may [...] - With a little help from with
You know the old saying:
with (JavaScript) {
metaprogramming.is(’possible’);
}
I’m going to leave the discussion of what constitutes metaprogramming to another day (read: never), but what I will say is that I’m becoming more interested in DSLs and fluent interfaces. I want the code I write to work at a very high level, where [...] - Announcing Ojay, the nice way to use YUI
I’ve been wanting to talk about this project for weeks if not months, and now I finally can. the OTHER media (the web shop I work for) is open-sourcing Ojay, a project I’ve been developing on-and-off since I started at the company back in October. It’s a wrapper for the core DOM, event, animation and [...]
- 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 [...]
- 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 = [...]