Roy Truelove
Roy Truelove

Reputation: 22456

Simple variable assignment not working

I have what looks like to me to be a simple variable assignment not working.

This code is in jQuery, for the context see here.

I'm calling:

$('#foo').on('someEvent', eventHandlerFn);

And I get this issue within the jQuery on function. Here's the starting point:

enter image description here

As you can see from the console below the code, selector is set the my eventHandlerFn and the fn variable is undefined. This is as expected.

On line 3509, the value of selector is assinged to fn. So, the value of fn should be same as the value of selector, no??

See below - selector is defined, as expected, but fn is still undefined. Why?

enter image description here

The end result is that my event handler is never registered.

Upvotes: 2

Views: 758

Answers (3)

Roy Truelove
Roy Truelove

Reputation: 22456

This seems to be an issue with the debugger in Chrome - either a material problem or just a nuance of the debugger that I don't understand. fn does have a value toward the end of the call, but not where the breakpoint is.

Upvotes: 1

Gabriele Petrioli
Gabriele Petrioli

Reputation: 195992

The code runs well as shown in the following two screens (the issue is on how chrome sets the context to the console)

It looks like console has access to the variable at definition time (in this case the passed parameters) and not the live values as you run the code

Before the swap

Before running the line

After the swap

After running the line

Upvotes: 2

lebolo
lebolo

Reputation: 2150

I'm not seeing any problem with this jsFiddle. Feel free to edit the jsFiddle to get it to look more like your code.

Can you try putting in console.log(fn); after line 3510 and rerunning? Maybe it's just a problem with the debugger?

Upvotes: 1

Related Questions