From c518df57e7b441d7e63cc13cf9f61326f3e5eba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Mon, 8 Aug 2011 12:43:47 +0000 Subject: [PATCH] make constructors created by OpenLayers.Class call the parent's initialize method rather the parent constructor, this is to accomodate usage patterns of IGN's GeoPortal API, r=ahocevar (closes #3454) git-svn-id: http://svn.openlayers.org/trunk/openlayers@12215 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/BaseTypes/Class.js | 2 +- tests/BaseTypes/Class.html | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/OpenLayers/BaseTypes/Class.js b/lib/OpenLayers/BaseTypes/Class.js index 23c7a6278f..a1f3495b54 100644 --- a/lib/OpenLayers/BaseTypes/Class.js +++ b/lib/OpenLayers/BaseTypes/Class.js @@ -37,7 +37,7 @@ OpenLayers.Class = function() { var C = typeof F.initialize == "function" ? F.initialize : - function(){ P.apply(this, arguments); }; + function(){ P.prototype.initialize.apply(this, arguments); }; if (len > 1) { var newArgs = [C, P].concat( diff --git a/tests/BaseTypes/Class.html b/tests/BaseTypes/Class.html index ebbe09249a..2079ce6d5f 100644 --- a/tests/BaseTypes/Class.html +++ b/tests/BaseTypes/Class.html @@ -432,27 +432,26 @@ t.eq(b.a, "bar", "ctor overwritten"); } - // This test doesn't currently pass. - /* function test_overwrite_5(t) { // overwrite constructor of parent class, which itself // doesn't defined "initialize" - t.plan(1); + t.plan(2); var A = OpenLayers.Class({ initialize: function() { this.a = "foo"; } }); var B = OpenLayers.Class(A, {}); + var _A = A; A = overwrite(A, { initialize: function() { this.a = "bar"; } }); var b = new B; + t.ok(A.prototype === _A.prototype, "A and _A share the prototype"); t.eq(b.a, "bar", "ctor overwritten"); } - */ function test_overwrite_6(t) { // with static methods