I am not sure what I am doing wrong here, or if I am misunderstanding let vs var/this as per https://www.w3schools.com/js/js_let.asp Hopefully somebody can explain.
The below sample code demonstrates the problem:
testObjectScope(){
let localObject=this.testObject;
localObject["c"]="charlie";
return localObject;
}
with output in developer console in first line of function:
this.testObject: Object
a: "alpha"
b: "bravo"
__proto__: Object
then at the return line:
this.testObject: Object
a: "alpha"
b: "bravo"
c: "charlie"
__proto__: Object
localObject: Object
a: "alpha"
b: "bravo"
c: "charlie"
__proto__: Object
however I would expect 'let' should not be able to change the object property (ie be a deep copy) and it should be this:
this.testObject: Object
a: "alpha"
b: "bravo"
__proto__: Object
localObject: Object
a: "alpha"
b: "bravo"
c: "charlie"
__proto__: Object
so does 'let' not declare a variable within the function that cannot be accessed anywhere else. Therefore when the function is done and scope is away from function how is it changing the localObject property create a change with testObject