javascript - JS - passing by reference an object -


given code below create object called foo , want make 'a' equal true function called maketrue(obj).

var foo = {a: false, b: false, c: false}   function maketrue(obj)  {  obj = true;      }   maketrue(foo.a); // want make 'a' true function   console.log(foo.a); 

why return false still?

i have looked @ similar questions worked passing object method doesn't pass reference.

you're not passing object argument (that passed reference), you're passing in boolean value of object's property (pass value).

if want work:

 var foo = {a: false, b: false, c: false}   function maketrue(obj, val)  {  obj[val] = true;      }   maketrue(foo, 'a'); // want make 'a' true function   console.log(foo.a); 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -