[OpenLayers-Dev] 2.10 and 2.11-RC1 OpenLayers.Class behavior
changes
Eric Lemoine
eric.lemoine at camptocamp.com
Tue Aug 2 07:52:07 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.
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20110802/66706eaa/overload.html
More information about the Dev
mailing list