I would want to set the elements of an array of a struct in its creation. Is it possible?
Now, in the first I’ve to define the struct and then set the array
function struct(a, b) {
this.a=a;
this.b=b;
}
var foo = [
new struct(1,2),
new struct(3,4),
]
but I would want an anoynymous function, anything like:
var foo = function(a, b) [
(1,2),
(3,4),
]
Note: it’s incorrect but you see the idea
What you want to use is the object literal notation in addition to the array literal notation.
If you really want to call a function, you have to give it a name (though it can be a short one):
You don’t need to use the
newkeyword to create a new object; you can set up a new instance—and even set the prototype-based inheritance—all within a normal function call.