The other day, I came across some weird code:
var OrderSupplement = function() {
oid: null;
code: "";
description: "";
startdate: "";
enddate: "";
gender: null;
cardowner: null;
box: null;
divisor: 0;
created: null;
createdBy: "";
};
The intention of the code was clear to me: It was the try to define a constructor function, in order to create an instance of OrderSupplement.
I am baffled by this syntax.
The buddy, who wrote the code, said it worked fine - although it obviously does not; at least it does not what it should. He instantiated a new instance of OrderSupplement and set e.g. oid to a nonnull value and retrieved it later. Of course retrieving a value before setting would have unveiled the bug.
The effect of the code above is like:
var OrderSupplementJson = function() {}
My question is:
Why is the code above accepted and does not throw an (syntax) error of any kind?