JSFiddle - React, Tailwind, and code Playground
JavaScript
function Thing(params) {
var that = this;
this.OtherObject = function OtherObject(param) {
this.param = param;
}
this.Foo = function Foo() {
this.bar = [];
this.add = function(item) {
if (this.bar.length != 0) {
for (var i = 0, len = this.bar.length; i < len; i++) {
if (this.bar[i].param <= item.param) {
this.bar.splice(i, 0, item);
}
}
} else {
this.bar[0] = item;
console.log(this.bar);
}
}
this.pop = function() {
return this.bar.pop();
}
this.length = function() {
return this.bar.length;
}
}
this.someFunc = function() {
var myThing = new that.Foo();
myThing.add(new that.OtherObject(3));
while (myThing.length() > 0) {
var someVar = myThing.pop();
}
}
}
var myThing = new Thing({
myParam: "someValue"
});
myThing.someFunc();