Skip to content

Commit

Permalink
Added nested matching for classes (requires constructor.super_,) Late…
Browse files Browse the repository at this point in the history
…st revision of node supports this.
  • Loading branch information
jfd committed Dec 8, 2009
1 parent e840e26 commit 5f81796
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions match.js
Expand Up @@ -70,8 +70,12 @@ var Match = (function() {
// Function (class constructor) resolver.
Function: function(ctor) {
return function(value) {
if(!value || value.constructor !== ctor) throw NO_MATCH;
return [value];
var c = value !== undefined ? value.constructor : undefined;
if(c) {
if(c === ctor) return [value];
while((c = c.super_)) if(c === ctor) return [value];
}
throw NO_MATCH;
}
},

Expand Down

0 comments on commit 5f81796

Please sign in to comment.