[OpenLayers-Dev] Strange behaviour in OpenLayers

Gael Lafond G.Lafond at aims.gov.au
Wed Dec 8 21:20:44 EST 2010


Hello,

First, I'm not sure if this mailing list is the proper way to ask
questions or submit bugs, but, so far, it's the only way I found.

My question is about inheritance in open layer. I used the new function
"OpenLayers.inherit = function(C, P)", from the Revision 10862, and it
do not inherit as I would expect.

Let say I define a class A with a method f and a class B also with a
method f:
A = OpenLayers.Class({
	initialize:function() {},
	f: function() {...}
});

B = OpenLayers.Class({
	initialize:function() {},
	f: function() {...}
});

I want B to inherit from A:
OpenLayers.inherit(B, A);

When I create a new instance of B and call the method f, the called
method is f from Class A instead of the one from Class B. The method
override from the subclass do not seems to occur.

Note that the inheritance works properly when it's specified in the
creation of the class.

Here is a complete example of the strange behaviour:

// Superclass A
A = OpenLayers.Class({
	initialize:function() {},
	f: function() { alert('A'); }
});

// Class B, inherit from Superclass A using the inherit function
B = OpenLayers.Class({
	initialize:function() {},
	f: function() { alert('B'); }
});
OpenLayers.inherit(B, A);

// Class C, inherit from Superclass A inline
C = OpenLayers.Class(A, {
	initialize:function() {},
	f: function() { alert('C'); }
});

var b = new B();
b.f(); // Should alert B, but alert A instead

var c = new C();
c.f(); // Alert C as expected


Is it a bug or an expected behaviour?

Thanks

Gael
-- 
Gael Lafond
Programmer
Australian Institute of Marine Science (AIMS)
PMB 3
Townsville MC
QLD 4810
Ph: +61 7 4753 4207
E-Mail: g.lafond at aims.gov.au


--  
------------------------------------------------------------------------
The information contained within this transmission is for the
use of the intended recipient only and may contain confidential
and/or legally privileged material and/or material the subject
of copyright and/or personal information and/or sensitive
information that is subject to the Privacy Act 1988. Any review,
re-transmission, disclosure, dissemination or other use of, or
taking of any action in reliance upon, this information by
persons or entities other than the intended recipient is
prohibited. If you have received this email in error please
notify the AIMS Privacy Officer on (07) 4753 4444 and delete
all copies of this transmission together with any attachments.
------------------------------------------------------------------------


More information about the Dev mailing list