From 8e4b06effd0ef33376bc39c2122a76431d45e7b0 Mon Sep 17 00:00:00 2001 From: Schuyler Erle Date: Fri, 6 Oct 2006 15:32:38 +0000 Subject: [PATCH] Added Class.inherit, changed Class.create to make it unnecessary to check for arguments.length > 0 in initialize(). git-svn-id: http://svn.openlayers.org/trunk/openlayers@1647 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/BaseTypes.js | 30 ++++++++++++++++++++++++++---- tests/list-tests.html | 1 + 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/OpenLayers/BaseTypes.js b/lib/OpenLayers/BaseTypes.js index 1ec0a027ce..e52a94f8e0 100644 --- a/lib/OpenLayers/BaseTypes.js +++ b/lib/OpenLayers/BaseTypes.js @@ -4,13 +4,35 @@ /* OpenLayers.Class metaclass */ OpenLayers.Class = { - create: function() { - return function() { - this.initialize.apply(this, arguments); + isPrototype: function () {}, // magic anonymous value + + create: function() { + return function() { + if (arguments && arguments[0] != OpenLayers.Class.isPrototype) + this.initialize.apply(this, arguments); + } + }, + + inherit: function () { + var super = arguments[0]; + var proto = new super(OpenLayers.Class.isPrototype); + for (var i = 1; i < arguments.length; i++) { + if (typeof arguments[i] == "function") { + var mixin = arguments[i]; + arguments[i] = new mixin(OpenLayers.Class.isPrototype); + } + OpenLayers.Util.extend(proto, arguments[i]); + } + return proto; } - } }; +/* + OpenLayers.Class.inherit( OpenLayers.Layer.Grid, OpenLayers.Layer.HTTPRequest, { + some stuff + }); +*/ + /********************* * * * PIXEL * diff --git a/tests/list-tests.html b/tests/list-tests.html index d44c02a7a3..cf4740722d 100644 --- a/tests/list-tests.html +++ b/tests/list-tests.html @@ -1,4 +1,5 @@