Preventing Lazy Evaluation In Function Called By Fabric.js
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 ad
Solution 1:
It does appear to be about lazy evaluation/closures.
Using this beautiful answer (Javascript: Creating Functions in a For Loop), I was able to craft a solution. Posting here in the hopes it will be useful to others. See the linked answer for why it works.
var fxnArr = [];
for( var p = 0; p < rows.length; p++ ) {
fxnArr[fxnArr.length] = (function(val) { returnfunction(){
window.location.href = "mylink" + "/" + val;
} })(p);
}
for (var p = 0; p<2; p++) {
varobject = new fabric.Circle({ radius: 10, top: 10 + 20 * p, left: 10 });
object.on('selected', fxnArr[p] );
canvas.add(object);
}
Post a Comment for "Preventing Lazy Evaluation In Function Called By Fabric.js"