JSFiddle - React, Tailwind, and code Playground
JavaScript
var a = function(){
var instance, A, updateLength;
instance = this;
A = [];
this.length = 0;
updateLength = function()
{
instance.length = A.length;
}
this.add = function(x){
A.push(x);
updateLength();
};
this.remove = function(){
var popped = A.pop();
updateLength();
return popped;
};
};
var x = new a();
x.add(1);
x.add(2);
x.add(3);
x.add(4);
alert("x.len :: " + x.length); // 2
alert("CurrItem :: " + x.remove()); // 4
alert("x.len :: " + x.length); // 1
alert("CurrItem :: " + x.remove()); // 3
alert("x.len :: " + x.length); // 1