I know I am doing something egregiously wrong in using the namespaces. I am posting this question after researching a ton in the net / google searches. Still can’t find what I am doing wrong. Can you please help me out? This is what I have   Javascript  Javascript file1  (function (js_namspace1, $, undefined) {     js_namespace1.n1function1 = function(){        var return_obj = {          return_function_to_call: “n1function_name2”          return_function_to_call_namespace: “js_namespace1”        }       js_namespace2.n2function1(return_obj)     }     Js_namespace1.n1function_name2 =function(list_of_names){         Js_namespace1.list_of_names = list_of_names         // do some processing to js_namespace1. list_of_names     } } (window. js_namspace1 = window. js_namspace1|| {}, jQuery ));   Javascript file2  (function (js_namspace2, $, undefined) {     js_namespace2.n2function1(return_obj) = function(return_obj){     js_namespace2.return_function_to_call =     return_obj.return_function_to_call     js_namespace2.return_function_to_call_namespace = return_obj.  .return_function_to_call_namespace      // do some processing     Js_namespace2.list_of_names = []     Js_namespace2. list_of_names.push(value_name)     window[js_namespace2.return_function_to_call_namespace][js_namespace2.return_function_to_call]( Js_namespace2.list_of_names);   } } (window. js_namspace2 = window. js_namspace2|| {}, jQuery ));   Html  From html file1 call js_namespace1.n1function1 based on end user clicking a field  // js_namespace1.n1function1 calls js_namespace2.n2function1 and displays another html file2  // In html file2 process the data (collect value of names) and then call the return function Js_namespace1.n1function_name2  In Js_namespace1.n1function_name2, process Js_namespace1.list_of_names(array), but when I do this, it also changes in Js_namespace2.list_of_names  For example when I do  Js_namespace1.n1function_name2.push(add_another_name), and then call js_namespace1.n1function1  (which in turn calls js_namespace2.n2function1).  Js_namespace2.list_of_names contains the value of add_another_name.   Please note that when js_namespace2.n2function1 is called from js_namespace1.n1function1 the array is not passed as parameter.  My expectation was when js_namespace1.n1function1 calls js_namespace2.n2function1 it would not update Js_namespace2.list_of_names with the add_another_name.   Can you please explain what is happening? most importantly point out any mistakes that I should be avoiding in this design (namespace, exchange of parameters between function calls). Am I using the namespace correctly in javascript – any best practices to recommend?
330
The primitive types (number, string, etc.) are passed by value, but objects are unknown, because they can be both passed-by-value (in case we consider that a variable holding an object is in fact a reference to the object) and passed-by-reference (when we consider that the variable to the object holds the object itself).  Although it doesn't really matter at the end, I want to know what is the correct way to present the arguments passing conventions. Is there an excerpt from JavaScript specification, which defines what should be the semantics regarding this?
115050
What is the correct output (meaning correct by the ECMA standard) of the following program?  function nl(x) { document.write(x + "&lt;br&gt;"); } nl(Function.prototype); nl(Function.prototype.prototype); nl(Function.prototype.prototype == Object.prototype); nl(Function.prototype.prototype.prototype);   Chrome and IE6 agree in saying:   function Empty() {} null for Chrome / undefined for IE6 false   and then crashing.  Mozilla outputs:  function () { } [object Object] false undefined   Are either of these correct? It seems that the Mozilla one does better, but that the best output is  function () { } [object Object] true undefined
6080
I'm new to both JavaScript and . In YUI library examples, you can find many uses of this construct:  (function() {     var Dom = YAHOO.util.Dom,     Event = YAHOO.util.Event,     layout = null,         ... })();   I think the last couple of parentheses are to execute the function just after the declaration.  ... But what about the previous set of parentheses surrounding the function declaration?  I think it is a matter of scope; that's to hide inside variables to outside functions and possibly global objects. Is it? More generally, what are the mechanics of those parentheses?
588
JavaScript allows functions to be treated as objects--if you first define a variable as a function, you can subsequently add properties to that function.  How do you do the reverse, and add a function to an "object"?  This works:  var foo = function() { return 1; }; foo.baz = "qqqq";   At this point, foo() calls the function, and foo.baz has the value "qqqq".  However, if you do the property assignment part first, how do you subsequently assign a function to the variable?  var bar = { baz: "qqqq" };   What can I do now to arrange for bar.baz to have the value "qqqq" and bar() to call the function?
85789
I'm trying to use this code to replace spaces with _, it works for the first space in the string but all the other instances of spaces remain unchanged. Anybody know why?  function updateKey() {     var key=$("#title").val();     key=key.replace(" ","_");     $("#url_key").val(key); }
121551
I have a function called:  void initializeJSP(string Experiment)   And in my MyJSP.h file I have:  2: void initializeJSP(string Experiment);   And when I compile I get this error:     MyJSP.h:2 error: variable or field initializeJSP declared void   Where is the problem?
113059
LWC rookie here, How can we call a JavaScript function from LWC? For example I have the following static resource helloWorld.js and I'll like to use and call the function in the file. How can I accomplish this?   JavaScript file:      function helloWorld(name) {         let hello = 'Hi ' + name;         return hello     }   LWC controller:   import { LightningElement, track, api } from "lwc";  import helloWorld from "@salesforce/resourceUrl/helloWorld";  import { loadScript } from "lightning/platformResourceLoader";   export default class testLwc extends LightningElement {    @track message;    renderedCallback() {     Promise.all([loadScript(this, helloWorld)])       .then(() =&gt; {         this.error = undefined;         // Call back function if scripts loaded successfully         console.log('load correctly')       })       .catch(error =&gt; {        });   }    handleOnChange() {        //how can I do something like this below ?      this.message = window.helloWorld('test');     }   Thank you
53521
What JavaScript keywords (function names, variables, etc) are reserved?
75057
Is there a way in C# to import everything inside a namespace like there is in Java with the wildcard character?  import java.awt.*;
107998
Is it like...  var obj = new Object();  obj.function1 = function(){     //code }   or something like that?
12181
Is there a best-practice or common way in JavaScript to have class members as event handlers?  Consider the following simple example:  &lt;head&gt;     &lt;script language="javascript" type="text/javascript"&gt;          ClickCounter = function(buttonId) {             this._clickCount = 0;             document.getElementById(buttonId).onclick = this.buttonClicked;         }          ClickCounter.prototype = {             buttonClicked: function() {                 this._clickCount++;                 alert('the button was clicked ' + this._clickCount + ' times');             }         }      &lt;/script&gt; &lt;/head&gt; &lt;body&gt;     &lt;input type="button" id="btn1" value="Click me" /&gt;     &lt;script language="javascript" type="text/javascript"&gt;         var btn1counter = new ClickCounter('btn1');     &lt;/script&gt; &lt;/body&gt;   The event handler buttonClicked gets called, but the _clickCount member is inaccessible, or this points to some other object.  Any good tips/articles/resources about this kind of problems?
6507
This is something that I always find a bit hard to explain to others:  Why do XML namespaces exist?  When should we use them and when should we not? What are the common pitfalls when working with namespaces in XML?   Also, how do they relate to XML schemas? Should XSD schemas always be associated with a namespace?
66844
How do you combine two jQuery search results? eg:  var $allFoos = $('.foo'),     $allBars = $('.bar')     $allFoosAndBars = $allFoos + $allBars;   Obviously, I just made up that last line, but I hope it makes it sorta clear what I mean. To be clear, the example is greatly simplified, and it could be any arbitrary sets i'm talking about, so $('.foo, .bar') is not what I'm after.
29956
For the longest time, I have wanted to understand why the browser adds an empty space between rendered HTML elements when there is a NewLine between them, for example:  &lt;span&gt;Hello&lt;/span&gt;&lt;span&gt;World&lt;/span&gt;   The html above will output the “HelloWorld” string without a space between “Hello” and “World”, however in the following example:  &lt;span&gt;Hello&lt;/span&gt; &lt;span&gt;World&lt;/span&gt;   The html above will output a “Hello World” string with a space between “Hello” and “World”.  Now, I have no problem accepting that this is just the way it works period, but the thing that bugs me a little is that I was always under the impression that spaces (or newlines) between the html elements would not matter at the time when the browser rendered the html to the user.  So my question is if anyone knows what the philosophical or technical reason behind this behavior.  Thank you.
56223
Any idea why the piece of code below does not add the script element to the DOM?  var code = "&lt;script&gt;&lt;/script&gt;"; $("#someElement").append(code);
15322
I come from a Java background, where packages are used, not namespaces. I'm used to putting classes that work together to form a complete object into packages, and then reusing them later from that package. But now I'm working in C++.  How do you use namespaces in C++? Do you create a single namespace for the entire application, or do you create namespaces for the major components? If so, how do you create objects from classes in other namespaces?
39454
Why do we need both using namespace and include directives in C++ programs?  For example,   #include &lt;iostream&gt;  using namespace std;  int main() {  cout &lt;&lt; "Hello world"; }   Why is it not enough to just have #include &lt;iostream&gt; or just have using namespace std and get rid of the other?  (I am thinking of an analogy with Java, where import java.net.* will import everything from java.net, you don't need to do anything else.)