A implementation of the fake-operator-overload inheritance. (http://www.2ality.com/2011/12/fake-operator-overloading.html) Just for fun
(function(root) { | |
var current = { | |
parent: null, | |
config: null, | |
}; | |
function clazz(name) { | |
function Class(config) { | |
if (this instanceof Class) | |
return this.init.apply(this, arguments); | |
current.parent = Class; | |
current.config = config || {}; | |
} | |
Class.classname = name; | |
function result(proto) { | |
Class.prototype = proto || Class.prototype; | |
window[name] = Class; | |
} | |
result.valueOf = function valueOf() { | |
var config = current.config; | |
var proto = Object.create(current.parent.prototype); | |
Object.keys(config).forEach(function(prop) { | |
proto[prop] = config[prop]; | |
}); | |
proto.constructor = Class; | |
Class.prototype = proto; | |
window[name] = Class; | |
}; | |
return result; | |
} | |
root.clazz = clazz; | |
})(this); |
This comment has been minimized.
This comment has been minimized.
Wonder what would happen if this idea is mixed with the jsBase .base() method? :P |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Based on the idea found here: http://www.2ality.com/2011/12/fake-operator-overloading.html