Can someone explain how this works. An object checks to see if it has been instantiated, and if it hasn't, then instantiates itself. It reminds me of a singleton, but I am not sure if I understand this code correctly.
var circularBuffer = function (size) {
if (this instanceof circularBuffer) {
this.size = size;
this.clear();
} else {
return new circularBuffer(size);
}
};