MartinWhite (4) [Avatar] Offline
#1
Hi,

I have been working on creating a TypeAheadSuggest component using the Refactored version of yours in Chapter 10. I downloaded your source files from the website and got it all working with the XML no problem.

One thing I noticed though, was that the prototype.js file that came with your source code was a bit old (version 1.3.1), so I tried replacing it with the latest version (1.5.1.1). However when I did I started getting an error message (in Firebug) saying ".extend() is not a function". I had to go back to the old version of prototype.js.

I looked at the two versions side by side, but could not work out what was causing the problem. Have you any ideas?

The part of the code triggering the error was this bit:

setOptions: function(options) {
this.options = {
suggestDivClassName: 'suggestDiv',
suggestionClassName: 'suggestion',
matchClassName : 'matchedtext',
matchTextWidth : true,
selectionColor : '#b1c09c',
matchAnywhere : false,
ignoreCase : false,
count : 10
}.extend(options || {});
<--------------------------------------- error
},


Great book by the way. I just getting into AJAX, and the your book has been a fantastic help.
davecrane (149) [Avatar] Offline
#2
Re: CH10 prototype.js error - extend() is not a function
Hi Martin,

In prototype.js v 1.3 and below, extend() was added as a method of Object.prototype, so that any JS object had a method extend(). This upset a lot of people because the method would turn up as a property of the object when being iterated over using a for loop - which meant that introducing prototype often broke code that worked before.

So, in prototype.js v1.4+, they changed extend() to being a static method of Object. So, instead of writing

myObject.extend(myOtherObject)

one would now write

Object.extend(myObject,myOtherObject)

The only downside of this is that code written for Prototype 1.3 will break under Prototype 1.4.

HTH

Dave
MartinWhite (4) [Avatar] Offline
#3
Re: CH10 prototype.js error - extend() is not a function
Thanks very much for your quick reply.

I have changed the code and it works fine with Prototype 1.5.1 now.

Cheers,
Martin
davecrane (149) [Avatar] Offline
#4
Re: CH10 prototype.js error - extend() is not a function
Cool, glad to be of service. smilie

If you're looking at type-ahead components for production use, you might also want to take a look at the AutoCompleter controls that ship with Scriptaculous, Prototype's sister library of UI bits'n'pieces. But if our code doers what you need, that's good too...

Dave
MartinWhite (4) [Avatar] Offline
#5
Re: CH10 prototype.js error - extend() is not a function
I've been meaning to take a look at the scriptaculous stuff anyway, so I'll have a play with their autocompleter.

Thanks again.
MartinWhite (4) [Avatar] Offline
#6
Re: CH10 prototype.js error - extend() is not a function
Hello Dave,

It was good advice to take a look at the Scriptaculous autocompleter. After a bit of messing about solving 'too much recursion' errors, I got it up and running.

It lacked one of the features of your control that I liked - emphasising the typed letters in the results list, but I managed to add that in myself.

Mart
janebush08 (2) [Avatar] Offline
#7
Re: CH10 prototype.js error - extend() is not a function
Thats great news Mart...thanks for the update.....

asp net 2.0 migration