Created
April 1, 2009 15:38
-
-
Save roykolak/88746 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Micro = (function() { | |
var proxy = function() {}; | |
var wrap = function(zuper, fn) { | |
return function() { | |
var saved = this.zuper; | |
this.zuper = zuper; | |
try { | |
return fn.apply(this, arguments); | |
} finally { | |
this.zuper = saved; | |
} | |
}; | |
}; | |
var classMethods = { | |
extend: function(constructor) { | |
var fn = wrap(this, constructor || function() {}); | |
proxy.prototype = this.prototype; | |
fn.prototype = new proxy; | |
fn.prototype.constructor = fn; | |
for (var name in classMethods) | |
fn[name] = classMethods[name]; | |
return fn; | |
}, | |
include: function(properties) { | |
var klass = this; | |
for (var name in properties) { | |
klass.prototype[name] = (function() { | |
var zuper = klass.prototype[name]; | |
var value = properties[name]; | |
if (!zuper || typeof value != 'function') | |
return value; | |
return wrap(zuper, value); | |
})(); | |
} | |
return klass; | |
} | |
}; | |
var base = function() {}; | |
base.extend = classMethods.extend; | |
return base; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment