tags:

views:

48

answers:

2

I want to do something like :

function validateBody($obj)
{

}

$ojb.keyup(validateBody($ojb));

How to do it the right way?

+2  A: 

I believe this is what you want, correct?

function validateBody(obj, number) {
  //do something...
}

$ojb.keyup(function() {
  var someNumber = getNumberFromAlgorithm();
  validateBody($(this), someNumber)
});
tj111
No,I want to pass arbitrary parameter to it.
Misier
Where is this arbitrary parameter coming from? Can you explain in more detail?
tj111
It's a number generated by some algorithm.
Misier
More like that? I'm still not sure where the number is created, how it exists in the context, etc so I have to make very generalized guesses here.
tj111
Seems you don't know how to pass a parameter:(
Misier
Seems like you don't know how to word your questions.
tj111
You are asking unrelated things too much.
Misier
+1  A: 

This will do what you are looking for:

function validateBody(e) {
    var $obj = e.data.obj;

    // do something
}

$ojb.bind('keyup', { obj: $ojb }, validateBody);

Check out the documentation on event.data and bind

Marve