I have this script below, which is triggered on button click:
<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>
Why is it that t.item's value always loops, instead of generating a new one with none value?
var test = function(){this.item=[];}andtest.prototype.doSomething = function(i){ this.item.push(i); return this.item;}function Test() {this.item = [];}). See stackoverflow.com/a/16751343/560114 and also bennadel.com/blog/….