0

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 ?

2
  • Can you post the code you have so far? Commented Apr 16, 2010 at 15:18
  • Redundant code is 100 lines and so not willing to post it. Commented Apr 16, 2010 at 15:39

1 Answer 1

4

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

function myFunction() {
  ...
}

and then call it wherever you like :

myFunction();
Sign up to request clarification or add additional context in comments.

5 Comments

This is not working for me. I am getting some wierd errors messages
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 ?
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.
Yes. I am defining function on a object, also is that the best practice of doing it or not ?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.