brad's life - JavaScript [entries|archive|friends|userinfo]
Brad Fitzpatrick

[ website | bradfitz.com ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

JavaScript [Mar. 23rd, 2005|12:10 pm]
Previous Entry Add to Memories Share Next Entry
I've been doing a lot of JavaScript the past couple days, trying to expand my horizons.

Holy crap, man.

I'm pretty smart, but this shit is hard. Between IE, Moz/Firefox, and Safari/Konq, I've seen everything. I'm now educated in quirks mode, strict mode, the different box models, the different event registration models, the different DOMs, the different ......

Very little's the same between browsers.

After getting stuff working 95% of the way in Moz and IE (props to x2vnc), Safari mostly worked, except for the part that does real work. Instead I get:

(timer):Null value

That's it. No line numbers. No context. No backtrace. That's the extent of Safari's debug output, even after jumping through hoops to make it even log that.

So I sprinkle alerts in. My event handler, a closure, has a numeric captured variable now replaced by the target of the event. What!? All the other alerts in the code show that the variable was only ever numeric, up to the point where I returned an anonymous function using that variable.

So I installed Konqueror 3.3.2 on my Debian box, to see what it did, just for shits. Sure enough, it's buggy (or obeying different "standards") in the same way that Safari is. But Konqueror goes down more than whitaker's mom (but not as well), so that's not helping.

I still remain optimistic that I'll learn all this, it'll make sense, I'll write some compatibility wrappers, and I'll only target the wrapper. If a browser can't do something, it gets the old HTTP-only behavior, and only a modern browser (or IE 6.0) gets the fun stuff.

Here's hoping my optimism lives.
LinkReply

Comments:
[User Picture]From: separated
2005-03-23 08:14 pm (UTC)

(Link)

oh, that was a dirty joke.
[User Picture]From: brentdax
2005-03-23 08:16 pm (UTC)

(Link)

Aren't standards wonderful? There are so many to choose from!
[User Picture]From: caladri
2005-03-23 08:37 pm (UTC)

(Link)

whitaker's mom is standardized?
[User Picture]From: granting
2005-03-23 09:06 pm (UTC)

(Link)

At least give old Tenne some credit!
[User Picture]From: jproulx
2005-03-23 08:24 pm (UTC)

(Link)

Cue sherm
From: sherm
2005-03-23 09:31 pm (UTC)

(Link)

Which one ya' looking for? The "AJAX is a waste of time" one, or the "Nobody who counts uses anything but MSIE" one?

The first one doesn't really apply because, well, it's Brad and not some dickhead web designer or tech executive who wants to Change The World and invent The Next Big Thing.

The second was only true pre-spyware and firefox-as-recation-to-spyware.

:P
[User Picture]From: xevinx
2005-03-23 08:27 pm (UTC)

(Link)

I remember a JavaScript nightmare similiar to that when trying to add custom lj stuff to the rich text editor.
[User Picture]From: mart
2005-03-23 08:30 pm (UTC)

(Link)

I don't really know if this could apply in the situation you're describing, but remember that JavaScript's concept of scope is based on a list of objects, and there are a lot of places where new scope objects get implicitly added to the list. One good example of this is with event handlers, where the object that triggered the event or the event itself become the top of the scope list. This behavior differs wildly between browsers, as you're coming to expect.

Also, some browsers pass the event that was raised as the first parameter to an event handler, while others (such as IE) don't pass anything to the event handler and require you to get it out of some variable in the current scope. This particular one caught me out when I was writing that shitty color picker.

The main reason I brought all this up was because you said you were getting an event object in an unexpected place. This is just a couple of event-related gotchas that probably don't have anything to do with it. ;) If you're going to write compatability wrappers, make sure to keep the wrapper thin; all of the wrappers I've seen before have ended up trying to do too much and have been several times larger than the script I was writing, so I just ditched them and handled the few applicable parts myself, inline.

[User Picture]From: brad
2005-03-23 10:01 pm (UTC)

(Link)

It's the scope chain that was the issue.

I worked around it, but I'm reading my "JavaScript: The Definitive Guide; 4th edition" again so I fully understand what happened.
[User Picture]From: youngoat
2005-03-23 10:31 pm (UTC)

(Link)

Dude. "that shitty color picker" is pretty cool. =]
[User Picture]From: nick
2005-03-23 08:43 pm (UTC)

I'm pretty smart, but...

(Link)

Anytime I hear that I can't help but expect the next thing to come out of that person's mouth to be absolutley retarted (I'm mean obviously not in this case since I have no idea what the hell you are talking about). Expressions like that just makes me think middle aged woman talking to a mechanic or something... "I'm a relatively intelligent person, but I just don't understand why you want me to change my oil if I still have plenty left"
[User Picture]From: mart
2005-03-23 09:11 pm (UTC)

Re: I'm pretty smart, but...

(Link)

A similar phrase is “I don't mean to be rude, but…”.

I don't know how people think that phrase can make them immune to causing offense.

From: evan
2005-03-23 09:38 pm (UTC)

Re: I'm pretty smart, but...

(Link)

No offense, but...
[User Picture]From: casey
2005-03-23 09:48 pm (UTC)

Re: I'm pretty smart, but...

(Link)

I'm not sure where my pants are, but regardless...
From: sherm
2005-03-23 09:51 pm (UTC)

Re: I'm pretty smart, but...

(Link)

With all due respect...
[User Picture]From: dakus
2005-03-23 10:29 pm (UTC)

Re: I'm pretty smart, but...

(Link)

Trust me...
[User Picture]From: koehlerk
2005-03-23 10:39 pm (UTC)

Re: I'm pretty smart, but...

(Link)

"don't mean to get off topic but..."
[User Picture]From: adamthebastard
2005-03-23 11:18 pm (UTC)

Re: I'm pretty smart, but...

(Link)

You're a great friend but...
[User Picture]From: grumpy_sysadmin
2005-03-24 01:28 am (UTC)

Re: I'm pretty smart, but...

(Link)

[User Picture]From: meowpurrr
2005-03-23 10:28 pm (UTC)

Re: I'm pretty smart, but...

(Link)

because an intention to cause insult is half of the crime. you're only responsible for someone being offended if you're offending them deliberately. of course, then there's sarcastic use of those phrases, which negates them again.. :>
[User Picture]From: endquote
2005-03-23 08:48 pm (UTC)

(Link)

It's better than it used to be. I was big into JS/DHTML stuff back in the day, trying to do crazy shit in Netscape 4. I eventually got sick of writing more code to handle browser versions and settled on Flash, which I still think is better for those types of applications. I won't go back to JS until there are tools and libraries that handle those incompatibilities for me.

(That said, I assume you're familiar with Venkman.)
[User Picture]From: cyberpigue
2005-03-23 08:56 pm (UTC)

(Link)

Surely you are aware of w3schools, but just in case..

http://www.w3schools.com/js/default.asp
[User Picture]From: snej
2005-03-23 09:22 pm (UTC)

(Link)

If you send me an example that reproduces the bug, I can (a) see if it still happens in the current soon-to-be-released version of Safari, and (b) file a bug report if necessary.
[User Picture]From: brad
2005-03-23 10:02 pm (UTC)

(Link)

Thanks! I wrote a minimal test case but sure enough, it worked. So I'm still looking into it. I worked around it for now, but I'm sure it's just something I don't understand.
[User Picture]From: heydusty
2005-03-23 09:38 pm (UTC)

(Link)

Apropos...

"In Google we refer to the approach as alternatively The Pain or The
Excitement depending on whether or not you're working on a Safari bug."


-Chris Wetherell on the name Ajax via the dojo toolkit mailing list.

Where I work we are lucky in that we don't even support Safari. Maybe 2.0 and Tiger will help.
From: sherm
2005-03-23 09:53 pm (UTC)

(Link)

Hey, you should be thankful that MS was even that good at ripping off Netscape's technology.

If they'd REALLY had their way, you'd be writing a VBScript version of everything for MSIE. ;)
From: xiambax
2005-03-23 09:58 pm (UTC)

(Link)

konq! its alright, its just really secure, i wouldnt so much call them bugs. but why not just use firefox.
[User Picture]From: brad
2005-03-23 10:03 pm (UTC)

(Link)

Uh, I do. But my users use everything. And Konq was just to approximate Safari, which I'm also testing in.
From: xiambax
2005-03-23 10:12 pm (UTC)

(Link)

thats true, what users are you talk about, are you still working with lj or do you have a new project
[User Picture]From: grumpy_sysadmin
2005-03-24 01:34 am (UTC)

(Link)

Just for the record, the fact that I had to launch Safari just to set Firefox as my default browser under Mac OS X means that I am never, ever using that steaming pile of shit.
From: cjensen
2005-03-23 11:47 pm (UTC)

I see a need

(Link)

Maybe you should create a meta-language that compiles into JavaScript portably. So the language would have a clear and single definition of how everything works, and then the compiler would arrange to have it work the same on each JavaScript implementation.

Or solve world hunger. Shouldn't be much harder.
[User Picture]From: way2tired
2005-03-24 01:45 am (UTC)

(Link)

I _HATE_ doing js against Safari. Ugh.
[User Picture]From: avatraxiom
2005-03-27 03:34 pm (UTC)

(Link)

Yep. My solution is usually just to avoid events entirely. :-) Events suck, cross-browser.

Of course, I suppose that's not possible with jsdraw.

-Max