Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot read property 'apply' of undefined #47

Open
janhvingel opened this issue Jul 28, 2016 · 10 comments
Open

Uncaught TypeError: Cannot read property 'apply' of undefined #47

janhvingel opened this issue Jul 28, 2016 · 10 comments
Labels

Comments

@janhvingel
Copy link

Can you please help.
I am trying to use Easybutton in this leaflet solution: [http://dail.aws.dk/]
It uses jQuery to swith between 2 pages (address search and the leaflet map).

When I try to use Easybutton I get this error: "Uncaught TypeError: Cannot read property 'apply' of undefined" (easy-button.js:316).

Best regard
Jhv

@atstp
Copy link
Contributor

atstp commented Jul 28, 2016

That's odd. On line 316, apply is called on Function.prototype.bind, which is vanilla ES5 (compatibility tables and caniuse).

Are you running IE8 by any chance?

First, try two things:

  • Make sure you haven't clobbered Function.prototype.bind somewhere else in your code
  • Use EasyButton's constructors directly, skipping the factories; instead of calling L.easyButton, call new L.Control.EasyButton

Also, the page you linked in you message doesn't load EasyButton, if you want feedback on your code, please put together a minimal example the reproduces the issue and I'll be happy to help further!

@djmakwana
Copy link

Hi, I am using this with Prototype.js (v1.6.1) as part of Tapestry 5.3.8 java web application.
I am getting a similar problem where L.easyButton does return but it doesn't give me an instance of L.EasyButton. I have debugged this problem and find that because of Prototype the constructor is not getting called.
I have tried to create object by new L.EasyButton() but get following error on console.

Uncaught TypeError: L.EasyButton is not a constructor

Any idea why this could be? I am stuck with Prototype for now so have to find a workaround.

@atstp
Copy link
Contributor

atstp commented Sep 9, 2016

This is pretty odd. sometime this week i'll take a closer look with specific attention to prototype.

Have you had any luck in finding a workaround?

@djmakwana
Copy link

No I haven't.

@celdia
Copy link

celdia commented Nov 24, 2016

Hello
I am trying to use this very interesting librarie "EasyButton". But I have the same error:
TypeError: L.EasyButton is not a constructor
Have you fixed this issue?

@atstp
Copy link
Contributor

atstp commented Nov 24, 2016

Try using L.Control.EasyButton instead of L.EasyButton.

As an extension of L.Control, EasyButton is nested under that instead of directly under L. The factories are at the root just for convenience. Let me know if it works!

@atstp atstp added the bug label Nov 24, 2016
@cocoto
Copy link

cocoto commented Apr 11, 2017

I have the same error using PhantomJS to open my webpage (L.Control.EasyButton and L.easyButton)
No problem with native Chrome or Firefox.

@sgentile
Copy link

@atstp using new L.Control.EasyButton - however, I'm unsure of how I'm to pass the font awesome . icon as well as the callback

@atstp
Copy link
Contributor

atstp commented Nov 10, 2017

the docs, and the readme both have examples that should work for you.

is your question related to this thread?

@sgentile
Copy link

When I run the code - it errors on this: it doesn't know what L.Control.EasyButton is

L.easyButton = function(/* args will pass automatically */){
  var args = Array.prototype.concat.apply([L.Control.EasyButton],arguments);
  return new (Function.prototype.bind.apply(L.Control.EasyButton, args));
};

When I attempt to instead instantiate a new L.Control.EasyButton() it only takes the following:

interface EasyButtonOptions {
        position?: ControlPosition
        id?: string
        type?: 'replace' | 'animate'
        states?: EasyButtonState[]
        leafletClasses?: boolean
        tagName?: string
    }

how, this doesn't match the documentation, ie. where do I define the icon, etc... ie. my code looks like this:

const btn = L.easyButton('fa fa-erase', () -> {...}, 'Clear Map');

so if I was to use new L.Control.EasyButton( ? where is icon, function and text ?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants