input into javascript function -


How can I get a JavaScript function that correctly accepts a parameter?

I can work perfectly if I do not use the input parameter because I can:

  var x = MyFunction;   

But I have to do this

  var x = MyFunction (e);   

Then it breaks.

I tried to work around it by setting the input parameters around it, but I can not find anything to work on. how can I do this?

  var MyFunction = function {var otherResult = function ({warning ("hi"); }, Input, objToAlert = function () {return input; }; Return {objToAlert: objToAlert, input: input, otherResult: otherResult}} (); Var e1 = "test"; // var y = MyFunction (E); // It does not work if I add a parameter to the function - the moment I put brackets I get the problem var x = MyFunction; X.input = e1; // Here also can not set input x.objToAlert (); X.otherResult (); After the function definition, you enter  () , then    

That's why the function is called and MyFunction is actually a returned object by function, not the function itself.

Do this:

  var MyFunction = function () {// ...}; // not () here    

Comments