I have a trouble with serialization clipTo
function to JSON. When I'm loading my JSON into canvas, I see the following error in my console:
Uncaught ReferenceError: clipByName is not defined.
I'm using function from this link: http://jsfiddle.net/ZxYCP/198/;
How can I fix this error, or how to stringify
clipTo
function.
Now in JSON object I have this:
clipTo:"function (ctx) {
return _.bind(clipByName, currentCanvas.getItemByName(obj.name))(ctx);
}
here is my code:
document.getElementById('uploadText').addEventListener('click', function() {
var textObj = itextObject.objT();
textObj.id = time.getMilliseconds() + '_' + time.getMinutes() + random(0, 1000);
textObj.name = textObj.id;
textObj.clearObj = 'clear';
if (currentFlag.flag === 'mainFlag') { textObj.clipName = 'clippingElem'; } else if (currentFlag.flag === 'mainFlagB') {
textObj.clipName = 'clippingElemB';
}
textObj.clipTo = function(ctx) { return _.bind(clipByName, currentCanvas.getItemByName(textObj.name))(ctx); };
currentCanvas.getItemByName(currentFlag.flag).set({ clipFor: textObj.clipName });
textObj.left = currentCanvas.getItemByName(currentFlag.flag).left;
currentCanvas.add(textObj);
currentCanvas.renderAll();
});
i had changed fiddle, and have the same error: http://jsfiddle.net/ZxYCP/749/