olivernn / lunr.js

A bit like Solr, but much smaller and not as bright
http://lunrjs.com
MIT License
8.96k stars 548 forks source link

typeerror 'undefined' is not an object on ipad #51

Closed digitalica closed 11 years ago

digitalica commented 11 years ago

lunr (including demo site) fails to work on ipad. After enableing the debug console of Safari, the error above shows (no line nr)

its a first generation ipad, model MB294LL, running IOS 5.1.1 (9B206) Safari version (found using www.watismijnip.nl) 5.1, Websit/534.46, Mobile/9B206 Safari/7534.48.3

my project uses lunr 0.4.1 (just as the demo page does now)

digitalica commented 11 years ago

started debugging

adding window.onerror = function (desc,page,line,chr) { alert('Error:'+desc +" at line: " +line); }

shows the error with line nr 0 twice at loading.... Hmmm. Not really helpful.

adding console.log("here wee are") shows issue is not directly in lunr file, but only after calling lunr.

adding more and more shows first error is in the lunr.Index = function()... at:

this.on('add', 'remove', 'update', (function () { this._idfCache = {} }).bind(this))

commenting these lines out prevents all errors...

digitalica commented 11 years ago

the problem is the bind method is missing. see

http://stevehavelka.com/blog/2013/03/bind-safari-mobile/ https://github.com/datorklubben/Spelprogrammering-med-JavaScript-och-Canvas/pull/4

The last link adds a cutom bind if the bind function is not there... It does the trick for me but i'm not sure if its solid enough to add to lunr itself...


Function.prototype.bind || (Function.prototype.bind = function(thisObj/_, ...boundArgs_/)
{
  var fn        = this
  var boundArgs = Array.prototype.slice.call(arguments, 1)

  return function(/_...args_/)
  {
    var args = Array.prototype.slice.call(arguments)
    return fn.apply(thisObj, boundArgs.concat(args))
  }
})```

at least the code is here too now... It did help me on ipads!
digitalica commented 11 years ago

ok, ok, this was already mentioned:

lunr.js has no external dependencies, although it does require a modern browser with ES5 support. In older browsers you can use an ES5 shim, such as augment.js, to provide any missing JavaScript functionality.