Skip to main content.
August 13th, 2008

mootools 1.2 and parent

If I’m in the constructor of an extended mootools class, it’s simple to call the parent:


var Animal = new Class({
initialize: function(name, race) {
this.name = name;
this.race = race;
},
doSomething: function() {
console.debug('make a sound');
}
});

var Cat = new Class({
Extends: Animal,
initialize: function(name) {
this.parent(name, ‘cat’);
}
});
What if you want to call a parent method? The reply lies in the following line of the Extends mutator:


self[key]._parent_ = previous;

So, here’s a small class to use with Implements to have a nice access to the parent methods:


var ParentCall = new Class({
_parent: function(name) {
return this[name]._parent_.bind(this);
}
});

And here we have a brand new cat which uses this:


var Cat = new Class({
Extends: Animal,
Implements: ParentCall,
initialize: function(name) {
this.parent(name, 'cat');
},
doSomething: function() {
this._parent('doSomething')();
console.debug('a "meow", to be exact.');
}
});

Posted by mattia as Uncategorized at 12:58 PM CEST

No Comments »

March 16th, 2008

Two

Long time no see, uh?

Two things. First one; it’s obvious that in C# we have that Assert.Equals(none, “string”) does not raise whether Assert.IsTrue(string.Equals(none, “string”)) raises, right?

Second thing. A small script that, given a set of css you downloaded from a site, reconstruct the tree of dependencies it has (through the url instruction). No, why are you thinking I’m copying someone else’s layout? Bad boys!

cat *.css | grep url | sed ’s/^.*url(\([^”)]*\)).*$/\1/’ | while read path ; do if ! test -f $path ; then mkdir -p `dirname $path` ; wget “http://www.volll.com/css/`dirname`” -O $path ; fi ; done

Caveats: does only consider url(xxx), and not url(”xxx”); works only for relative links.

Posted by mattia as Uncategorized at 10:53 AM CET

No Comments »