/    Sign up×
Community /Pin to ProfileBookmark

A bug in firefox? What is going on with this code?

I am creating a rather large AJAX-enabled site and using Prototype as my main framework. Everything was fine but recently I stumbled upon some VERY weird behavior. In this block of code:

[CODE]
#1: if (typeof x == ‘object’) {
#2: if (typeof x.activate == ‘function’)
#3: x.activate();
#4:
#5: Event.stop(e);
#6: }
[/CODE]

What happens is that execution seems to skip from line #1 to line #5, even when the initial if fails! For example, if x is undefined, then the if condition will obviously fail, and execution should jump to after line #6. Instead, it goes inside the if, completely skips lines #2 and #3, and goes to line #5.

I wish I could show you the rest of the code, but it’s pretty complex and I don’t think it would show much. I can’t see anything wrong in this code or any of the surrounding code. This function that I show above, btw, is called by Prototype’s Event.observe() function. So, unless there is some bug with Prototype’s observe function, I can’t for the life of me understand this.

Has anyone ever had anything similar happen to them?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@rootApr 24.2007 — Stepping thru the code...

#1: if(typeof x== 'object)

this must be the issue as the object is skipping lines 1 to 5 which means that the item isnt an object...

#2: if(typeof x.activate == 'function')

this is also another issue because the x.activate must be a 'function' inorder for the function to be triggered, so in oreder for this to fail, the item isnt a function.

so I would check exactly what it is your passing to this function.
×

Success!

Help @Amberite spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...