JavaScript javascript passing event in closure javascript passing event as parameter,javascript passing event to function,

I was trying the following:

f.addEventListener('submit',(function(frm){
var func = (function(e){somefunction(e,frm);})(e);
})(f),false);

But this is failing. I want to pass the form (f) as a static reference and the dynamic event object to the named function 'somefunction'.

What I have above isnt working, what is the right syntax for passing both?

Answer:1

The issue is that each of the functions is being called right away, with undefined actually being passed to addEventListener().

You'll want to instead return one of the functions without its calling parenthesis so the event can call it later:

f.addEventListener('submit', (function (frm) {
    return function (e) {
        someFunction(e, frm);
    };
})(f), false);

Though, with event bindings, you may not necessarily need the closure, as the <form> will be the context (this) of the function passed:

f.addEventListener('submit', someFunction, false);

function someFunction(e) {
    var frm = this;
    // ...
}
Answer:2

so, I came across a bug and thought it was interesting. Once I sat and thought about it for 5 seconds, it made sense but curious how one would get past it in the future. so, I have some hashes set up ...

so, I came across a bug and thought it was interesting. Once I sat and thought about it for 5 seconds, it made sense but curious how one would get past it in the future. so, I have some hashes set up ...

i have hiddentfield whose value is changing on javascript. I just wanted to fire serverside event valuechanged event of hiddenfield when its value changed from javascript. I tried with : ...

i have hiddentfield whose value is changing on javascript. I just wanted to fire serverside event valuechanged event of hiddenfield when its value changed from javascript. I tried with : ...

  1. fire server side event from javascript asp.net
  2. fire server side event from jquery
  3. fire server side event from javascript
  4. how to fire server side event for html checkbox
  5. fire server side click event from javascript
  6. how to fire server side event on click of the button
  7. event doesn't fire server side

I want to add a custom attribute for each object in my canvas. I did that using: fabric.Object.prototype.toObject = (function (toObject) { return function () { return fabric.util.object....

I want to add a custom attribute for each object in my canvas. I did that using: fabric.Object.prototype.toObject = (function (toObject) { return function () { return fabric.util.object....

  1. fabricjs custom attributes
  2. fabricjs add custom attributes

I want to delete * characters if it is present in a string. This is my code but it's not working. String.replace(/*/g '')

I want to delete * characters if it is present in a string. This is my code but it's not working. String.replace(/*/g '')

  1. replace characters string python
  2. replace characters string javascript
  3. replace characters string c#
  4. replace characters string java
  5. replace characters string matlab
  6. replace characters string powershell
  7. replace characters string vba
  8. replace characters string array java
  9. replace string characters
  10. replace string characters in r
  11. replace string characters php
  12. replace string characters swift
  13. replace string characters in stata
  14. replace string characters ruby
  15. replace string characters sed
  16. replace characters in string bash
  17. replace characters in string sql
  18. replace characters in string js
  19. replace characters in string online
  20. replace all characters string javascript