[OpenLayers-Dev] [strk@keybit.net: [OpenLayers-Users] Style
context as an object ?]
strk
strk at keybit.net
Mon Jul 12 05:38:03 EDT 2010
On Tue, Jul 06, 2010 at 02:46:58PM -0600, Tim Schaub wrote:
> On 7/6/10 2:47 AM, strk wrote:
> > Guys, I'm forwarding this as I think what I'm trying to do
> > is limited by actual OL code.
> >
> > Basically I'm trying to use an "instance object" as the
> > 'context' for a Style.
> >
>
> If you want to use the "this" keyword in methods on the context object,
> you have two options:
>
> 1) Bind the methods explicitly (untested code).
>
> var context = {
> foo: function() {
> return this.works;
> },
> works: true
> };
> for (var key in context) {
> var val = context[key];
> if (typeof val === "function") {
> context[key] = OpenLayers.Function.bind(val, context);
> }
> }
Works perfectly, thanks.
I won't be patching BaseType, as I'll really need different methods to
be bound to different scopes (context will be composed by contexts defined
by multiple "style plugins").
--strk;
() Free GIS & Flash consultant/developer
/\ http://strk.keybit.net/services.html
More information about the Dev
mailing list