7

Every assignment is done by reference in JavaScript... like why? Lemme use a pointer when I need it.
ES2016 looks so much like Java, I swear nobody will notice if they added pointers... and over 9000 more confusing features.

Comments
  • 1
    It doesn't just end by adding a pointer. This will change the whole structure of the language itself.
  • 2
    @tahnik RN, I need to do JSON.parse(JSON.stringify(myVar)) to make a value copy
  • 1
    @ryzokuken I don't understand it though. You are converting a JS object to json string and converting it back to JS object again? Why?
  • 4
    @tahnik so that the variable I am assigning this to gets the value and not the reference to the other variables. Sometimes, one needs to deliberately copy the value of a variable and not change the original. I hope this made it clear?
  • 1
    @ryzokuken Oh you are assigning it to another variable to make a copy. I get it now. Yeah, I understand. It can be weird sometimes.
  • 2
    Lodash :) use lodash clone function :p
  • 7
    You can use Object.assign({}, varYouWantToClone).
  • 0
    @spongessuck thanks for the tip
  • 1
    @ryzokuken sure thing. Be careful, though, I don't think it's supported in old IE.
  • 3
    @spongessuck that won't make a deep copy.
  • 0
    Won't function cp( x ){ return x;} make a value copy for you?
  • 0
    Noob question here... What does a pointer change vs a reference?
Add Comment