Upon clicking a button, I have the following script that triggers:
<button>Click</button>
<script>
var test = function(){};
test.prototype = {
item:[]
};
$(document).ready(function(){
$("button").on('click',function(){
var t = new test();
t.item.push(1);
console.log(t.item);//[1],[1,1],[1,1,1]
});
})
</script>
Could you explain why the value of t.item keeps looping instead of generating a new one without any previous values?