From 001b54865c583a65657bba62582da5162139b332 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 21 Aug 2007 16:15:59 +0000 Subject: [PATCH] prototype: Ensure that classes always have an initialize method. --- CHANGELOG | 2 ++ src/base.js | 3 +++ test/unit/base.html | 3 +++ 3 files changed, 8 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 5eef4dd..8833204 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Ensure that classes always have an initialize method. [Mislav Marohnić] + * Update Template, Selector, Ajax.*, and ObjectRange classes to use the new class system. [Mislav Marohnić] * Change Abstract.TimedObserver to subclass PeriodicalExecuter and tweak its subclasses to use new inheritance functionality. TimedObserver can now be stopped the same way as PeriodicalExecuter. Closes #8589. [Mislav Marohnić] diff --git a/src/base.js b/src/base.js index 1ff14cc..922d45c 100644 --- a/src/base.js +++ b/src/base.js @@ -21,6 +21,9 @@ var Class = { } if (properties) Class.extend(klass, properties); + if (!klass.prototype.initialize) + klass.prototype.initialize = Prototype.emptyFunction; + klass.prototype.constructor = klass; return klass; diff --git a/test/unit/base.html b/test/unit/base.html index bc62f5a..e1a51cb 100644 --- a/test/unit/base.html +++ b/test/unit/base.html @@ -415,6 +415,9 @@ assertEqual('Nibbles: Hi!', pet.say('Hi!')); assertEqual(Animal, pet.constructor, "bad constructor reference"); assertUndefined(pet.superclass); + + var Empty = Class.create(); + assert('object', typeof new Empty); }}, testInheritance: function() { with(this) {