[OpenLayers-Dev] Re: Strange behaviour in OpenLayers

Xavier Mamano (jorix) xavier.mamano at gmail.com
Thu Dec 9 13:32:20 EST 2010


Hi Gael,

"OpenLayers.inherit" is a new method that is used internally in Class. It
can be used directly, but not as you use it. If you use "OpenLayers.inherit"
should not use "Class". Use "OpenLayers.inherit" is not the normal way of
working with OpenLayers.

See example:


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

// Class B, inherit from Superclass A using the OpenLayers.inherit function
B = function() {alert("New B")};
OpenLayers.inherit(B, A, {
    b: "B",
    f: function() { alert('B from ' +this.super);}
});
// Class BB, inherit from class B using OpenLayers.Class()
BB = OpenLayers.Class(B, {
    initialize: function() {alert("New BB from " + this.b)},
    f: function() { alert('BB from ' +this.super); }
});

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

var b = new B(); // Alert "New B"
b.f(); // Alert "B from A" 

var c = new C(); // Alert "New B"
c.f(); // Alert "C from A" as expected

var bb = new BB(); // Alert "New BB from B" as expected
bb.f();// Alert "BB from A" as expected


Note: Not to be confused with "OpenLayers.Class.inherit" function that is
deprecated.



Xavier Mamano

Gael Lafond wrote:
> 
> 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.
> 
> ...
> 

-- 
View this message in context: http://osgeo-org.1803224.n2.nabble.com/Strange-behaviour-in-OpenLayers-tp5817644p5820025.html
Sent from the OpenLayers Dev mailing list archive at Nabble.com.


More information about the Dev mailing list