javascript - Why does the assignment operator return a value and not a reference? -


I explained the example given below and I thought both answers could be 20 and not back 10. He wrote that both commas and assignments give a value, not references. I do not quite understand what that means.

I understand the passage in the work or methods near the variable, that is, by the primitive type reference, passed by value and objects, but I am not sure how this applies in this case. is.

> I also understand the value of the reference and the value of 'this' (after the help of stack overflow), but in both cases I still thought that I still apply it as a method I am doing foo.bar () which means foo is the reference but it seems that both functions result in the call bar ()

Why is this and what does all this mean?

  var x = 10; Var foo = {x: 20, bar: function () {this.x return;}}; (Foo.bar = foo.bar) (); // return 10 (foo.bar, foo.bar) (); // return 10  

It does not have to be of value vs. references, Code> with this value (as you suspect). In javascript, this is set is completely called function, no, where it is defined, you have one of three ways this Set the value:

  1. Call the function through object properties using property accelerator notation, either dotted signaling ( obj.foo () ) or bracketed Notation ( obj ["foo"] () ).
  2. The function is called an object property by using the call statement (actually there is only one version of # 1, but worth the call, especially this source Code
  3. / Li> / code> the value, global object, and therefore x your foo The object comes from somewhere else is another way of thinking that what this code is R is:

      var f = foo.bar; // is not calling it, in this context F (); // Global Object  

    , if you do not use the property instead of calling directly (instead of value property and then to call with it), this handling does not kick inside.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -