This answer gives a helpful explication of how to add a "link" (really, an event that redirects to a URL) to a particular object rather than to all objects on the canvas:
How to add URL to an image in Fabric.js?
However, when placed inside a loop that generates multiple objects, it only links to the last object created's value.
Here's an example:
for (var p = 0; p<2; p++) {
var object = new fabric.Circle({ radius: 10, top: 10 + 20 * p, left: 10 });
object.on('selected', function() {
window.location.href = "mylink" + "/" + p;
})
canvas.add(object);
}
This will have both objects linking to "mylink/1", when what I want is for the first object to link to "mylink/0" and the second to link to "mylink/1".
My Javascript skills are stuck in 1999, but this looks like a lazy loading problem to me. How do I force the object created from each loop to have its own function?