Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 ALL


  Deep clone of JavaScript object

In JavaScript world, it's frequently seen object clone. Normally when creating a clone of an object, it's only the reference being cloned but not all contents. In some scenarioes, it's desired to clone all the content instead of just the reference such that any change made to the cloned object will not change the original object.Differences between shallow clone and deep clone can be as simple as:Shallow clone : Only the object reference is cloned but not the contentDeep clone : Clone all content, including the content of the object referenced in the objectShallow clone implementationIt's rela...

10,928 0       JAAVSCRIPT SHALLOW COPY DEEP CLONE DEEP COPY SHALLOW CLONE


  A Python assignment trap

Python has no assignment, it only has reference. Assume, we have following code snippet:>>> values = [0, 1, 2]>>> values[1] = values>>> values[0, [...], 2]Why the result is not [0, [0, 1, 2], 2], instead it goes into an infinite loop? To understand this, we need to understand some basics about Python.Python has no variables, it only has labels. When we run:values = [0, 1, 2]Python will first create a list object [0,1,2], then it labels it as values. If we later run:values = [3, 4, 5]Python will then create a new list object [3,4,5] and it will tear off the values lab...

9,415 0       PYTHON TRAP ASSIGNMENT SHALLOW COPY