Alex Rivera | Logout

How to determine if a function has been called without setting global variable

Asked 2012-07-02T19:27:34.153
26

I am looking for a good technique to get away from what I am tempted to do: to set a global variable.

The first time someone runs a function by clicking a button it triggers an initial function to turn a few things into draggables. Later, if they click the button a second time I want to determine if the init function has been initialized, and if so to not call it again. I could easily do this by setting a global variable from the init function and then checking that variable from the click function, but I'm wondering how to do this without setting a global variable. I would really like an example of a way to do this.

Edit
Report

1 Answer

2

Why don't you just check to see if your draggables have a class of draggable on them?

if ($('.mydiv').is('.draggable')) {
     //do something
}
answered 2012-07-02T19:31:08.640

Your Answer