I was wondering if there was a way to pass arguments to first class functions in javascript. For example, I am trying to pass the function as a parameter to a higher order function, but the first class function takes an argument: document.addEventListener(&quot;keydown&quot;, myFunc);  But I want to do this without calling the first class function: document.addEventListener(&quot;keydown&quot;, myFunc(arg1));
4059
The situation is somewhat like-  var someVar = some_other_function(); someObj.addEventListener("click", function(){     some_function(someVar); }, false);   The problem is that the value of someVar is not visible inside the listener function of the addEventListener, where it is probably being treated as a new variable.
5575
I have the name of a function in JavaScript as a string. How do I convert that into a function pointer so I can call it later?  Depending on the circumstances, I may need to pass various arguments into the method too.  Some of the functions may take the form of namespace.namespace.function(args[...]).
29988
I have a problem with an object I have created that looks something like this:  var myObject = {      AddChildRowEvents: function(row, p2) {         if(document.attachEvent) {             row.attachEvent('onclick', function(){this.DoSomething();});         } else {             row.addEventListener('click', function(){this.DoSomething();}, false);         }     },      DoSomething: function() {         this.SomethingElse(); //&lt;-- Error here, object 'this' does not support this method.     } }   The problem is that when I am inside the 'DoSomething' function, 'this' does not refer to 'myObject' what am I doing wrong?
88330
I've seen some people using void operator in their code. I have also seen this in href attributes: javascript:void(0) which doesn't seem any better than javascript:;  So, what is the justification of using the void operator?
46765
Take the below code:  private void anEvent(object sender, EventArgs e) {     //some code }     What is the difference between the following ?  [object].[event] += anEvent;  //and  [object].[event] += new EventHandler(anEvent);   [UPDATE]  Apparently, there is no difference between the two...the former is just syntactic sugar of the latter.
109364
I have a method which takes params object[] such as:  void Foo(params object[] items) {     Console.WriteLine(items[0]); }   When I pass two object arrays to this method, it works fine:  Foo(new object[]{ (object)"1", (object)"2" }, new object[]{ (object)"3", (object)"4" } ); // Output: System.Object[]   But when I pass a single object[], it does not take my object[] as the first param, instead it takes its all elements like I wanted to pass them one by one:  Foo(new object[]{ (object)"1", (object)"2" }); // Output: 1, expected: System.Object[]   How do I pass a single object[] as a first argument to a params array?
96862
Aura Action javascript object has setCallback function that we use to communicate with the server. The first parameter of the function is scope. Aura documentation has the following explanation:  Scope : Object The scope in which the function is executed. You almost always want to set scope to the keyword this.  Experimenting with this keyword inside the component results in undefined when used inside controller.js and the helper object instance when used inside helper.js. Does someone know what the scope parameter is affecting? Using this feels wrong as it can be almost anything depending on the place in code the setCallback is executed from. P.S. currently I have problems with private attribute visibility inside the action callback function so I am trying to eliminate all possible causes.
62479
I am doing , and am having a few problems with function notation. I understand the form f(x).  What does the form f: x ↦ y mean? Could you also give one or two examples?  And, if possible, state your source. Thank you.
3033
I've always handled optional parameters in JavaScript like this:  function myFunc(requiredArg, optionalArg){   optionalArg = optionalArg || 'defaultValue';    // Do stuff }   Is there a better way to do it?  Are there any cases where using || like that is going to fail?
40166
Is there a way to use constants in JavaScript?  If not, what's the common practice for specifying variables that are used as constants?
82347
Okay, I'm aware that the standard dictates that a C++ implementation may choose in which order arguments of a function are evaluated, but are there any implementations that actually 'take advantage' of this in a scenario where it would actually affect the program?  Classic Example:  int i = 0; foo(i++, i++);   Note: I'm not looking for someone to tell me that the order of evaluation can't be relied on, I'm well aware of that. I'm only interested in whether any compilers actually do evaluate out of a left-to-right order because my guess would be that if they did lots of poorly written code would break (rightly so, but they would still probably complain).
86340
It's known that you should declare events that take as parameters (object sender, EventArgs args). Why?
51358
How do you decide between passing arguments to a method versus simply declaring them as object instance variables that are visible to all of the object's methods? I prefer keeping instance variables in a list at the end of the Class, but this list gets longer as my program grows. I figure if a variable is passed often enough it should just be visible to all methods that need it, but then I wonder, &quot;if everything is public there will be no need for passing anything at all!&quot;
107998
Is it like...  var obj = new Object();  obj.function1 = function(){     //code }   or something like that?
44431
Could you explain the difference between setting methods in the constructor and through prototype object? The following code shows these two ways of setting the methods - say_hello and say_bye both work fine:  function MessageClass() {   this.say_bye = function() { alert('see ya'); }; }  MessageClass.prototype.say_hello = function() { alert('hello'); };  x = new MessageClass(); x.say_hello(); x.say_bye();
92805
I have a class A and another class that inherits from it, B. I am overriding a function that accepts an object of type A as a parameter, so I have to accept an A. However, I later call functions that only B has, so I want to return false and not proceed if the object passed is not of type B.  What is the best way to find out which type the object passed to my function is?
4670
I have an element that already has a class: &lt;div class=&quot;someclass&quot;&gt;     &lt;img ... id=&quot;image1&quot; name=&quot;image1&quot; /&gt; &lt;/div&gt;  Now, I want to create a JavaScript function that will add a class to the div (not replace, but add). How can I do that?