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 [...]
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 [...]
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 [...]
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 [...]
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 = function(a,b,c) { return a + b [...]
Saq made a couple of comments on my ChainCollector article about how to queue up functions to respond to Ajax calls, and whether I could write something up to shed a bit of light on how this might be done. Today, I’m going to implement some methods that allow to GET from/POST to a URL, [...]
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 that calls the original [...]
Update, 25 February 2008: This class is now available as part of JS.Class (it’s called MethodChain now). It also forms a key part of Ojay, an expressive wrapper for YUI. Update, 12 Dec 2007: Another implementation change. A blank ChainCollector instance now has the following properties: then, and, ____ (formerly __enqueue) and fire. The method [...]
As everybody is no doubt aware, there are new rules for getting a patch into Rails. With that in mind, I thought I’d share some of my patches here in the hopes that one of my army of readers (ha!) will find something I wrote interesting enough to try out for themselves. I’ve got a [...]
Ruby’s open classes and modules, along with alias_method, make it really easy to add functionality to existing methods. Take this example from my plugin AttrLocked: class ActionView::Helpers::InstanceTag def tag_with_attribute_locking(name, options = nil) options = (options || {}).update(“disabled” => attribute_locked?) tag_without_attribute_locking(name, options) end alias_method(:tag_without_attribute_locking, :tag) alias_method(:tag, :tag_with_attribute_locking) end All that does is intercept any calls to [...]
© The If Works. Powered by WordPress using the DePo Skinny Theme.