Skip to content

Instantly share code, notes, and snippets.

@nw
nw / superhack.js
Created November 23, 2010 02:22 — forked from creationix/superhack.js
// Add a handy super call for all objects
MyBaseClass.prototype.super = function () {
var parent = this.__proto__.__proto__;
var caller = arguments.callee.caller;
var fn;
if (caller.prototype === this.__proto__) {
return parent.constructor.apply(this, arguments);
} else {
// This is probably quite slow, but it doesn't seem to affect
// performance too much in real tests.
Number.implement({
parsePermissions : function(){
var types = {r : 4, w : 2, x : 1 }, levels = {u : 1, g : 8, o : 64 }, perms = {};
for(l in levels){
for(t in types) perms[l+t] = !!(this & (levels[l] * types[t]));
}
return perms;
}
});