I've got a problem using the apply() method from Function.prototype.apply().
I'm trying to create a series of drawings on my CreateJS stage by passing arrays of arguments to the bezierCurveTo method using apply(). This will allow me to loop through about a hundred such sets of arguments and draw a full picture.
However, apply() isn't working on the bezierCurveTo method (it works on moveTo and lineTo).
Instead, I get
TypeError: this.append is not a function
Does anyone have any ideas about why this might be happening? I'm not clear on why it works on the other methods and not bezierCurveTo.
var myData = {
curveTo: [214.1, 853.1, 327.1, 903.7, 451.8, 903.7],
};
var sha = new createjs.Shape();
sha.graphics.bezierCurveTo.apply(myData.curveTo);
Thank you.
Edit:
Stack trace shows this is where the error lies:
p.moveTo = function(x, y) {
return this.append(new G.MoveTo(x,y), true);
};
So, I found an answer to this problem and wanted to follow up. Mad props to Halcyon for their patient guidance as I worked through this problem. The issue seems to be a combo of the way the library CreateJS maps these functions on to standard Javascript canvas methods. Because it is creating new objects, the apply operator won't work in this instance.
Read more here: Use of .apply() with 'new' operator. Is this possible?
Long story short, when using "new" operator, .apply() won't work as a way to expand an array as a series of arguments on a function call, no matter how you try to set the context.