From 9f09a8c791d5545d5bad6f592d503a9169801293 Mon Sep 17 00:00:00 2001 From: Andrew Dupont Date: Tue, 18 Nov 2008 22:28:06 -0600 Subject: [PATCH] Refactored class.js. --- src/lang/class.js | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/lang/class.js b/src/lang/class.js index 4a764cd..ab72b29 100644 --- a/src/lang/class.js +++ b/src/lang/class.js @@ -1,10 +1,10 @@ /* Based on Alex Arnell's inheritance implementation. */ -var Class = { - create: function() { +var Class = (function() { + function create() { var parent = null, properties = $A(arguments); if (Object.isFunction(properties[0])) parent = properties.shift(); - + function klass() { this.initialize.apply(this, arguments); } @@ -14,7 +14,7 @@ var Class = { klass.subclasses = []; if (parent) { - var subclass = function() { }; + var subclass = function() {}; subclass.prototype = parent.prototype; klass.prototype = new subclass; parent.subclasses.push(klass); @@ -25,15 +25,12 @@ var Class = { if (!klass.prototype.initialize) klass.prototype.initialize = Prototype.emptyFunction; - + klass.prototype.constructor = klass; - - return klass; + return klass; } -}; - -Class.Methods = { - addMethods: function(source) { + + function addMethods(source) { var ancestor = this.superclass && this.superclass.prototype; var properties = Object.keys(source); @@ -46,7 +43,7 @@ Class.Methods = { value.argumentNames().first() == "$super") { var method = value; value = (function(m) { - return function() { return ancestor[m].apply(this, arguments) }; + return function() { return ancestor[m].apply(this, arguments); }; })(property).wrap(method); value.valueOf = method.valueOf.bind(method); @@ -55,6 +52,13 @@ Class.Methods = { this.prototype[property] = value; } - return this; + return this; } -}; + + return { + create: create, + Methods: { + addMethods: addMethods + } + }; +})(); \ No newline at end of file