<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>