views:

38

answers:

1

I have piece of function which I am trying to call at two different places and so am thinking to put it inside a function and call that function at two different places.

I am not sure how this can be done using jQuery:

Any Sample examples would be appreciated ?

+4  A: 

you don't need to worry about jQuery - just define your function :

function myFunction() {
  ...
}

and then call it wherever you like :

myFunction();
oedo
This is not working for me. I am getting some wierd errors messages
Rachel
can you post these weird errors?
oedo
if I do call using `myFunction: function()` and then call using `this.myFunction()` than it works fine, what is the difference between two ways of calling a function ?
Rachel
`myFunction: function()` what do you mean by that? are you defining the function on an object? the simple syntax i gave in my answer is just for a global function that can be called from anywhere.
oedo
Yes. I am defining function on a object, also is that the best practice of doing it or not ?
Rachel
yeah that's certainly a good practice for object-oriented coding. the only caveat is if it means you have to pass loads of references to the object around, it might be easier to make it a normal, global, function.
oedo