i store initial state of "this" (global) scope shown in pseudo code below :
<script> var copiedobject = object.create(this); x="foo"; console.log(x); // foo </script>
and reset state later on using :
<script> = object.create(copiedobject); console.log(x); // undefined since it's copy before x assigned </script>
is correct way of cloning , using clone replace original later on ? instead of "refreshing" page of html5/javascript app , purge newly added functions ajax.
in code have posted, making shallow copy of object. properties of o1
copied reference o2
, if these complex types (objects). means:
var o1 = { a: { b: 1 } }, o2 = object.create(o1); o1.a.b = 10; console.log(o2.a.b) // 10
what need deep copy (so), might see, lead down deep rabbit hole.
Comments
Post a Comment