For example we have the following JavaScript code:  function f(o) {     o.message = "set in f";     o = {         message: "new object!"     };     console.log(`inside f: o.message="${o.message}" (after assignment)`); } let o = {     message: 'initial value' }; console.log(`before calling f: o.message="${o.message}"`); f(o); console.log(`after calling f: o.message="${o.message}"`);   In these particular lines  o = {     message: "new object!" };   we are creating new object with name 'o', but in the previous line  o.message = "set in f";   we are modifying attribute of the original object with name 'o' (hence modifying the object itself in my understanding).  My question is why does assignment behavior differ in these situations? Shouldn't it be the same for object itself and its attributes?  For example 'o' assignment in the function body should have changed the original 'o' object instead of creating new one.
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?
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?
23225
I am attempting to set a value in a textarea field using jquery with the following code:  $("textarea#ExampleMessage").attr("value", result.exampleMessage);   The issue is, once this code executes, it is not altering the text in the textarea?  However when performing an alert($("textarea#ExampleMessage").attr("value")) the newly set value is returned?
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
43165
Both uses of the \let primitive often lead to the same result. Is this even true for every case? What was the thought process behind it. And if they are actually not equivalent, are there particular situations in which you can only use one or the other?  Addendum  Summary  As your plenty and nice answers show, there are cases in which you clearly have to respect one of the variations (for instance regarding assignments to '=' and macros that check for spaces). These were totally understandable points and they explain a lot. Now, @Werner's answer confirmed one ingenuous thought of mine:     "The use of = is purely to emphasize the fact that an assignment is being made [...]"   Moreover Knuth himself seem to have intended the synopsis including the '=', though he also used the other way. Why did he include it then? It will probabilly have to do with the exact meaning of the TeX source snippet cited by @Werner. To be honest, I don't know WEB either, but if there is someone who does, can he explain it (in very easy terms) by adding an edit to his answer? New answers are clearly welcome too.  Side Note  As an element of a gray area I found an example where using the syntax including the equal sign causes "difficulties":  If you have control sequences which need the 'csname-expandafter' mechanism, and you want to stick to the minimal exploitation of \expandafter by saying  \expandafter\let\csname foo1\expandafter\endcsname\csname bar1\endcsname   you can't add an equal sign because it would distract TeX from reading the \expandafters correctly. To get the equal sign work you would need to use the slightly unhandier version  \expandafter\let\csname foo1\expandafter\endcsname\expandafter=\csname bar1\endcsname
71695
This code always works, even in different browsers:  function fooCheck() {   alert(internalFoo()); // We are using internalFoo() here...    return internalFoo(); // And here, even though it has not been defined...    function internalFoo() { return true; } //...until here! }  fooCheck();   I could not find a single reference to why it should work, though. I first saw this in John Resig's presentation note, but it was only mentioned. There's no explanation there or anywhere for that matter.  Could someone please enlighten me?
35414
In javascript you can easily create objects and Arrays like so:  var aObject = { foo:'bla', bar:2 }; var anArray = ['foo', 'bar', 2];   Are similar things possible in PHP? I know that you can easily create an array using the array function, that hardly is more work then the javascript syntax, but is there a similar syntax for creating objects? Or should I just use associative arrays?  $anArray = array('foo', 'bar', 2); $anObjectLikeAssociativeArray = array('foo'=&gt;'bla',                                       'bar'=&gt;2);   So to summarize: Does PHP have javascript like object creation or should I just use associative arrays?
13274
Does anybody have useful example of this assignment inside a C# method? I have been asked for it once during job interview, and I am still interested in answer myself.
52909
In order to return a value from a VB.NET function one can assign a value to the "Functions Name" or use "return value."  I sometimes see these inter-mixed in the same function.  Personally, I prefer the return.  My question is, what is the internal difference, if any, between the two?
89893
The __debug__ variable is handy in part because it affects every module. If I want to create another variable that works the same way, how would I do it?  The variable (let's be original and call it 'foo') doesn't have to be truly global, in the sense that if I change foo in one module, it is updated in others. I'd be fine if I could set foo before importing other modules and then they would see the same value for it.
108043
I'm seeing some unexpected behaviour with the locker service enabled when updating two fields on an object, one of which is nested inside a sub-object.   I have a lightning application that initialises a JavaScript object and passes references to fields on the object, and the object itself, as attributes to a contained component:  App Markup  &lt;aura:application &gt;     &lt;aura:attribute name="obj" type="object" /&gt;     &lt;aura:handler name="init" value="{!this}" action="{!c.init}" /&gt;      Top level value: &lt;ui:outputText value="{!v.obj.value1}" /&gt; &lt;br/&gt;     Nested value: &lt;ui:outputText value="{!v.obj.sub.value2}" /&gt; &lt;br/&gt;      &lt;c:MultiFieldTest obj="{!v.obj}" value1="{!v.obj.value1}" value2="{!v.obj.sub.value2}" /&gt;      &lt;br/&gt;      &lt;button onclick="{!c.showObj}"&gt;Show Object&lt;/button&gt; &lt;/aura:application&gt;   app controller  ({     init : function(component, event, helper) {         helper.init(component);     },     showObj : function(component, event, helper) {         helper.showObj(component);     } })   app helper:  ({     init : function(cmp) {         var obj={value1:'', sub:{value2:''}};         cmp.set('v.obj', obj);     },     showObj : function(cmp) {         alert('Object = ' + JSON.stringify(cmp.get('v.obj')));     } })   So the concept is there is an object with the structure:  {value1:'',   sub:{      value2:''} }   and I want to pass value1 and sub.value2 as attributes to a component that will update them. However, to ensure that the changes are propagated up and down the food chain (as per : ) I am also passing in the object itself. Essentially I want the contained component to update a couple of fields and propagate the changes without having to know which fields it is updating.  The containing component markup:  &lt;aura:component&gt;     &lt;aura:attribute name="value1" type="String" /&gt;     &lt;aura:attribute name="value2" type="String" /&gt;     &lt;aura:attribute name="obj" type="object"/&gt;      &lt;button onclick="{!c.setValues}"&gt;Set Values&lt;/button&gt;  &lt;/aura:component&gt;   controller:  ({     setValues : function(component, event, helper) {         helper.setValues(component);     } })   helper:  ({     setValues : function(cmp) {         var obj=cmp.get('v.obj');         console.log('Obj before = ' + JSON.stringify(obj));          cmp.set('v.value1', 'Value 1');         cmp.set('v.value2', 'Value 2');           obj=cmp.get('v.obj');         console.log('Obj after = ' + JSON.stringify(obj));          cmp.set('v.obj', obj);     } })   So when the user clicks the button, strings are set into the value1/value2 attributes and the underlying object 'reset' into the page. I then click on the 'Show Object' button, and the results are as expected with the locker service deactivated.   However, when I activate the locker service, only the second update 'sticks' and obj.value1 is empty, although both ui:outputText elements show the value1/value2 details as expected. What appears to be happening is that setting the first attribute updates the page as expected, and the object, but setting the second attribute updates the page and an earlier version of the object, minus the value1 details.  However, if I don't get the obj attribute at the beginning of the setValues method, it works:  setValues : function(cmp) {     // var obj=cmp.get('v.obj'); &lt;---- removed this      cmp.set('v.value1', 'Value 1');     cmp.set('v.value2', 'Value 2');       var obj=cmp.get('v.obj');     console.log('Obj after = ' + JSON.stringify(obj));      cmp.set('v.obj', obj); }   So pretty easy to work around, but I'm curious as to why this would be necessary with the locker service enabled - there's no secure versions of anything in play and the attributes are all accessible to the component. Its almost like the act of looking at the object fixes a version somewhere, and all updates retrieve that version before applying their update, rather than retrieving the latest version.
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.
102637
I am reading the book 'Practical Common Lisp' by Peter Seibel. In Chapter 6, &quot;Variables&quot; sections &quot;Lexical Variables and Closures&quot; and &quot;Dynamic, a.k.a. Special, Variables&quot;.  My problem is that the examples in both sections show how (let ...) can shadow global variables and doesn't really tell the difference between the Dynamic and Lexical vars. I understand how closures work but I don't really get whats so special about let in this example: (defvar *x* 10)  (defun foo ()   (format t &quot;Before assignment~18tX: ~d~%&quot; *x*)   (setf *x* (+ 1 *x*))   (format t &quot;After assignment~18tX: ~d~%&quot; *x*))   (defun bar ()   (foo)   (let ((*x* 20)) (foo))   (foo))   CL-USER&gt; (foo) Before assignment X: 10 After assignment  X: 11 NIL   CL-USER&gt; (bar) Before assignment X: 11 After assignment  X: 12 Before assignment X: 20 After assignment  X: 21 Before assignment X: 12 After assignment  X: 13 NIL  I feel like there is nothing special is going on here. The outer foo in bar increments the global x, and foo surrounded by let in bar increments the shadowed x. What's the big deal? I don't see how is this supposed to explain the difference between lexical and dynamic variables. Yet the book continues like this:  So how does this work? How does LET know that when it binds x it's supposed to create a dynamic binding rather than a normal lexical binding? It knows because the name has been declared special.12 The name of every variable defined with DEFVAR and DEFPARAMETER is automatically declared globally special.  What would happen if let would bind x using &quot;normal lexical binding&quot;? All in all, what are the differences between dynamic and lexical binding and how is this example special regarding dynamic binding?
33578
I'm learning the Python programming language and I've came across something I don't fully understand.   In a method like:  def method(self, blah):     def __init__(?):         ....     ....   What does self do?  What is it meant to be?  Is it mandatory?  What does the __init__ method do?  Why is it necessary? (etc.)  I think they might be OOP constructs, but I don't know very much.
647
I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent.  The previous developer used two ways of declaring functions and I can't work out if there is a reason behind it or not.  The two ways are:  var functionOne = function() {     // Some code };     function functionTwo() {     // Some code }   What are the reasons for using these two different methods and what are the pros and cons of each? Is there anything that can be done with one method that can't be done with the other?
15653
Possible Duplicate:          I'm looking to make a callable JavaScript object, with an arbitrary prototype chain, but without modifying Function.prototype.  In other words, this has to work:  var o = { x: 5 }; var foo = bar(o); assert(foo() === "Hello World!"); delete foo.x; assert(foo.x === 5);   Without making any globally changes.
38527
I'm just trying to streamline one of my classes and have introduced some functionality in the same style as the .  However, I'm a bit confused as to why __init__ is always called after __new__. I wasn't expecting this. Can anyone tell me why this is happening and how I can implement this functionality otherwise? (Apart from putting the implementation into the __new__ which feels quite hacky.)  Here's an example:  class A(object):     _dict = dict()      def __new__(cls):         if 'key' in A._dict:             print "EXISTS"             return A._dict['key']         else:             print "NEW"             return super(A, cls).__new__(cls)      def __init__(self):         print "INIT"         A._dict['key'] = self         print ""  a1 = A() a2 = A() a3 = A()   Outputs:  NEW INIT  EXISTS INIT  EXISTS INIT   Why?