I'm trying to create an object in which some properties rely on other previously defined properties, while trying to rely on object literals. Otherwise put, I'm trying to accomplish something like the following code (which is incorrect):
var mesh = {
offset : $('#mesh').offset(),
position : $('#mesh').position(),
height : win.height - this.offset.top - 12,
width : win.width - this.offset.left - 12,
limits : {}
}
as opposed to something of this sort (which works):
var mesh = {};
mesh.offset = $('#mesh').offset();
mesh.position = $('#mesh').position();
mesh.height = win.height - mesh.offset.top - 12;
mesh.width = win.width - mesh.offset.left - 12;
mesh.limits = {};
So my question is rather simple: what is actually wrong with the first block of code and how can I correct it in order to create those new properties based on previously defined ones?