Hi,
I'm still new to jQuery, but I have been playing with SlickGrid and
trying to integrate both it and jQuery with some JavaScript library
code that I had already developed. When I tried to integrate my code
with jQuery, I spent 2 frustrating hours trying to figure out what was
going on thanks to Firefox's descriptive (and apparently equivalent to
the famous BASIC 'syntax error') error message:
uncaught exception: [Exception... "String contains an invalid
character" code: "5" nsresult: "0x80530005
(NS_ERROR_DOM_INVALID_CHARACTER_ERR") location: ".../jquery-1.3.2.js
Line: 1026"]
After much wrangling, commenting, uncommenting, debugging, etc., I
discovered that the cause is an assumption in jQuery that Object
doesn't have any non-literal property values. For good or bad
JavaScript style, my library defines a couple of utility functions on
Object.prototype to assist in both debugging as well as prototypical
inheritance.
When jQuery does this:
181 // Check to see if we're setting style values
182 return this.each(function(i){
183 // Set all the styles
184 for ( name in options ) {
185 jQuery.attr(
186 type ?
187 this.style :
188 this,
189 name, jQuery.prop( this, options[ name ],
type, i, name )
190 );
191 }
192 });
What happens is that it attempts to set an attribute value name equal
to the definition of a function. Of course, there's all kinds of
invalid characters in there, so Firefox pukes the above error message.
Adding the following check prevents the error and allows adding
methods to Object instances.
181 // Check to see if we're setting style values
182 return this.each(function(i){
183 // Set all the styles
184 for ( name in options ) {
185 if ( typeof this[ name ] !== 'function' ) {
186 jQuery.attr(
187 type ?
188 this.style :
189 this,
190 name, jQuery.prop( this, options[ name ],
type, i, name )
191 );
192 }
193 }
194 });
I'm not sure what you think about the above, but it would be really
handy if this was fixed in the upstream jQuery codebase. I don't know
if anyone else has hit this problem or not, but it at least bears
recording for posterity in any case. :)
Cheers,
ast