[OpenLayers-Dev] 2.10 and 2.11-RC1 OpenLayers.Class behavior changes

RICHARD Didier didier.richard at ign.fr
Tue Aug 2 09:23:22 EDT 2011


> On Tue, Aug 2, 2011 at 12:54 PM, RICHARD Didier <didier.richard at ign.fr>
> wrote:
>>
>>>> This test has been ran on FF successfully.
>>>
>>> I haven't looked at your tests into detail, but do mean your problems
>>> are now solved?
>>>
>>
>> no, just meant it works with OL 2.11 under FF ... I have got problems
>> with
>> OL 2.10 !
>
> I fail to see where you're having problem. Sorry.
>

What about these cases ?

1/ var A= OpenLayers.Class({...})
A.staticFunction= function() { ... };
A= overload(A, { initialize: function() {...}});

2/ in test 4, if you remove the initialize function from B and overload A,
the B constructor is still the previous A's constructor. One can still
overload B using the initialize method (copying the whole source code),
but if one uses A.prototype.initialize, the classes' tree is modified.


regards,

didier

> Below are the overload function and the tests I've come up with. The
> tests pass with both OL 2.10 and OL trunk. I'd like to see a specific
> test that fails with OL 2.10.
>
>
>
> <html>
> <head>
>   <script src="http://openlayers.org/api/2.10/OpenLayers.js"></script>
>   <!--<script src="http://openlayers.org/dev/OpenLayers.js"></script>-->
>   <script type="text/javascript">
>
>     // the overload function under test
>     function overload(C, o) {
>         if (typeof o.initialize === "function" &&
>             C === C.prototype.initialize) {
>             // OL 2.11
>             var proto = C.prototype;
>             C = o.initialize;
>             C.prototype = proto;
>         }
>         OpenLayers.Util.extend(C.prototype, o);
>         return C;
>     }
>
>     function test_overload_1(t) {
>         // overload constructor
>         t.plan(1);
>         var A = OpenLayers.Class({
>             initialize: function() {
>                 this.a = "foo";
>             }
>         });
>         A = overload(A, {
>             initialize: function() {
>                 this.a = "bar";
>             }
>         });
>         var a = new A;
>         t.eq(a.a, "bar", "ctor overloaded");
>     }
>
>     function test_overload_2(t) {
>         // overload regular method
>         t.plan(1);
>         var A = OpenLayers.Class({
>             initialize: function() {
>             },
>             method: function() {
>                 this.a = "foo";
>             }
>         });
>         A = overload(A, {
>             method: function() {
>                 this.a = "bar";
>             }
>         });
>         var a = new A;
>         a.method();
>         t.eq(a.a, "bar", "method overloaded");
>     }
>
>     function test_overload_3(t) {
>         // overload constructor of subclass
>         t.plan(1);
>         var A = OpenLayers.Class({
>             initialize: function() {
>                 this.a = "foo";
>             }
>         });
>         var B = OpenLayers.Class(A, {
>             initialize: function() {
>                 A.prototype.initialize.call(this);
>             }
>         });
>         B = overload(B, {
>             initialize: function() {
>                 A.prototype.initialize.call(this);
>                 this.a = "bar";
>             }
>         });
>         var b = new B;
>         t.eq(b.a, "bar", "ctor overloaded");
>     }
>
>     function test_overload_4(t) {
>         // overload constructor of parent class
>         t.plan(1);
>         var A = OpenLayers.Class({
>             initialize: function() {
>                 this.a = "foo";
>             }
>         });
>         var B = OpenLayers.Class(A, {
>             initialize: function() {
>                 A.prototype.initialize.call(this);
>             }
>         });
>         A = overload(A, {
>             initialize: function() {
>                 this.a = "bar";
>             }
>         });
>         var b = new B;
>         t.eq(b.a, "bar", "ctor overloaded");
>     }
>
>   </script>
> </head>
> <body>
> </body>
> </html>
>
>
>
> --
> Eric Lemoine
>
> Camptocamp France SAS
> Savoie Technolac, BP 352
> 73377 Le Bourget du Lac, Cedex
>
> Tel : 00 33 4 79 44 44 96
> Mail : eric.lemoine at camptocamp.com
> http://www.camptocamp.com
>


-- 
RICHARD Didier - Chef du pôle technique du Géoportail
2/4, avenue Pasteur - 94165 Saint Mandé Cedex
Tél : +33 (0) 1 43 98 83 23


More information about the Dev mailing list