4 * Copyright 2003-2012, Moxiecode Systems AB, All rights reserved.
8 * This utilitiy class is used for easier inheritage.
11 * * Exposed super functions: this._super();
14 * * Property functions: var value = object.value(); and object.value(newValue);
18 define("tinymce/util/Class", [
21 var each = Tools.each, extend = Tools.extend;
23 var extendClass, initializing;
28 // Provides classical inheritance, based on code made by John Resig
29 Class.extend = extendClass = function(prop) {
30 var Self = this, _super = Self.prototype, prototype, name, member;
32 // The dummy class constructor
34 var i, mixins, mixin, self;
36 // All construction is actually done in the init method
40 // Run class constuctor
42 self.init.apply(self, arguments);
45 // Run mixin constructors
52 mixin.init.apply(self, arguments);
59 // Dummy function, needs to be extended in order to provide functionality
64 // Creates a overloaded method for the class
65 // this enables you to use this._super(); to call the super function
66 function createMethod(name, fn) {
68 var self = this, tmp = self._super, ret;
70 self._super = _super[name];
71 ret = fn.apply(self, arguments);
78 // Instantiate a base class (but only create the instance,
79 // don't run the init constructor)
81 prototype = new Self();
86 each(prop.Mixins, function(mixin) {
89 for (var name in mixin) {
90 if (name !== "init") {
91 prop[name] = mixin[name];
97 prop.Mixins = _super.Mixins.concat(prop.Mixins);
101 // Generate dummy methods
103 each(prop.Methods.split(','), function(name) {
108 // Generate property methods
109 if (prop.Properties) {
110 each(prop.Properties.split(','), function(name) {
111 var fieldName = '_' + name;
113 prop[name] = function(value) {
114 var self = this, undef;
117 if (value !== undef) {
118 self[fieldName] = value;
124 return self[fieldName];
131 each(prop.Statics, function(func, name) {
137 if (prop.Defaults && _super.Defaults) {
138 prop.Defaults = extend({}, _super.Defaults, prop.Defaults);
141 // Copy the properties over onto the new prototype
145 if (typeof member == "function" && _super[name]) {
146 prototype[name] = createMethod(name, member);
148 prototype[name] = member;
152 // Populate our constructed prototype object
153 Class.prototype = prototype;
155 // Enforce the constructor to be what we expect
156 Class.constructor = Class;
158 // And make this class extendible
159 Class.extend = extendClass;