I have the following Polymer element. On ready, I randomly assign a value
to the random attribute then push this to the deep array. If in my
demo.html, I instantiate three test-data objects, they will all have
different values for random. But the deep array will be identical for all
three. It contains the 3 randomly generated numbers, across the 3 instances.
Is this a bug? If I uncomment the line that reassigns deep to be an empty
array, it works correctly. But for my purposes won't really work. I want to
store a bunch of static data in an object but different instances should be
allowed to modify that data without affecting each other. Is my only option
to do an explicit deep-copy?
TEST-DATA.HTML
<polymer-element name="test-data" attributes="random deep">
<template>
<div>
{{random}} / {{deep}}
</div>
</template>
<script>
Polymer('test-data', {
random: null,
ready: function() {
this.random = Math.random();
//this.deep = [];
this.deep.push(this.random);
},
deep: [],
});
</script>
</polymer-element>
DEMO OUTPUT
3 `test-data` object:
0.11330667673610151 /
0.11330667673610151,0.5147093017585576,0.03896064590662718
0.5147093017585576 /
0.11330667673610151,0.5147093017585576,0.03896064590662718
0.03896064590662718 /
0.11330667673610151,0.5147093017585576,0.03896064590662718
Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups
"Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/polymer-dev/bcabb15d-dbd4-482b-bc7a-3dc668de0260%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.