Open SimonRichardson opened 11 years ago
It would be a lot easier if we could use Proxies or __noSuchMethod__
.
Because it's just a pain atm to try and implement this, we should leave it out until chrome gets Proxy. We could test to make sure that Proxy
is available, but again, it's a lot of hit just for syntax sugar.
//
// ## proxy
//
function proxy(ctor) {
return function(v) {
var value = isArray(v) ? v : [].slice.call(arguments);
return new Proxy(ctor(value), {
get: function(obj, prop) {
if (prop in obj) return obj[prop];
else if(!(prop in squishy)) throw new Error('NoSuchMethod ' + prop + ' on ' + squishy);
return function() {
var args = squishy.map([].slice.call(arguments), function(a) {
return squishy.extract(a);
});
return ctor.create(squishy[prop].apply(null, [squishy.extract(obj)].concat(args)));
};
}
});
};
}
Consider adding Seq or ArrayList as a way to extend Arrays with squishy methods.