Jump to content

[Possible] Fix for 'TypeError: undefined is not a function' in HTML5 games on iPad1 Safari


tyson
 Share

Recommended Posts

Hi all,  I finally found a fix for a bug that was plaguing me for months on the iPad1.

 

The mysterious 'TypeError: undefined is not a function'

 

Apparently Safari 5 doesn't have a native 'bind' method.

 

This isn't so apparent if you're using a framework.

 

The workaround involves using a shim:

 

https://gist.github.com/jussi-kalliokoski/978329

 

 

-Tys

Link to comment
Share on other sites

Well, the error you described occures if you try to call a property that is not a function.

 

For example:

 

var test = 1;test();> TypeError: number is not a function

 

Simple: "test" is of type number, not of type function.

 

And since the "bind()" method is not defined on a function object on iOS safari (as well as in a lot of other browsers), the property is of type "undefined", hence your error: "TypeError: undefined is not a function".

 

A solid suite of unit tests should help you covering such bugs very easily.

 

Interestingly I never heard of the bind() method at all and also never saw anyone using it :)

Link to comment
Share on other sites

This was specifically on iOS 5 Safari, where debugging was hell. 

Yeah not a noob, I've tried *all* types of online debuggers and they didn't pick up anything at all.

 

Didn't happen on Safari 6, where debugging was loads better. 

 

Bind was used mostly with keys and the mouse I suspect. Probably also with binding touch to mouse events too.

 

-Tys

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...