- ARCHIVE / Prototype
- PackR won’t touch your $supers
Another quick update: PackR received an update today that means that when you use its :shrink_vars mode, it won’t minify any variables called $super. In Prototype, $super is used to implement inheritance and your class definitions will break if you change its name.
I didn’t really want to make PackR inconsistent with Dean’s original, but without [...] - 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 = [...] - Using ChainCollector to respond to Ajax calls
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, [...]
- 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 [...] - Reiterate 1.3
Tiny update: after adding 16 characters (”this._object || “), Reiterate is now compatible with Prototype 1.6.0’s revised Hash API. Also, the gzipped copy is now even smaller, thanks to a different compression strategy. Essentially, when using Packer (or PackR for that matter), using ’shrink variables’ plus gzip compression will result in the smallest an fastest-to-execute [...]
- Where’s my inheritance?
Update: from what I can gather from going through the source code, $super in Prototype actually refers to the method in the parent class, rather than the old method in the current class. My point about the other libraries mentioned below stands, though. Also, my apologies to Dan, whom I cornered at @media Ajax and [...]
- JS.Class updates
Yes, it only came out a couple days ago, but it’s a 0.9.x release, so it’s still being developed. If you downloaded JS.Class over the last couple days, I strongly recommend you upgrade to the latest version.
First off, it improves performance substantially over the initial release by inspecting method definitions to find out if they [...] - Announcement: JS.Class
After mentioning Prototype’s inheritance model the other day, one rather important thing struck me about it. I was going to borrow their model for some of my own work when I realised that, if you use Prototype’s $super feature, your code will break if you compress it using a variable-shrinking algorithm (all the decent compressors [...]
- Prototype’s Function#wrap
So Prototype 1.6 has finally hit the streets, and it looks to be a very nice piece of work. Though I’m no longer using Prototype at my day job (we use YUI, plus a layer of syntactic sugar that I’m in the process of writing), I’m interested to see what is possible with the JavaScript [...]
- Reiterate 1.2: operators are (kind of) methods now!
You know how, in Ruby, + is a method? Well guess what:
// Count members within a range
numbers.findAll({’>': 4, ‘<=’: 27}).length// Remove items of a specific type
collection.reject(['instanceof', String])// Assign default values to a collection
[27, 0, 'prototype', '', true, false].map({’||’: ‘foo’})
// -> [27, "foo", "prototype", "foo", true, "foo"]
How’s about that then?