javascript - Why does my object not have a constructor? -
i writing few helper classes scripting adobe illustrator.
my problem starts in eyelet object. when instantiate it fails @ first new group()
because apparently group
doesn't have constructor.
here stripped down version of code:
/****************** collection class **********************/ function collection() { this.parent = app.activedocument; this.typename = "collection"; } collection.prototype.setname = function(name) { this.instance.name = name; }; /****************** group (extends collection) *****************/ function group(name, parent) { this.parent = parent || this.parent; this.instance = this.parent.groupitems.add(); if(name) { this.setname(name); } else { this.setname("group"); } } group.prototype = new collection(); /****************** shape class **********************/ function shape() { this.parent = app.activedocument; this.typename = "shape"; } shape.prototype.setname = function(name) { this.instance.name = name; }; shape.prototype.stroke = function(width, color) { this.instance.stroked = true; this.instance.strokeweight = width; this.instance.strokecolor = color; }; /****************** line (extends shape) **********************/ function line(parent, start, end) { this.instance = parent.pathitems.add(); // [ [startx, starty], [endx, endy] ] this.instance.setentirepath([start,end]); } line.prototype = new shape(); /****************** eyelet (extends shape) **********************/ function eyelet(parent, position) { this.instance = new group("eyelet", parent); var whitecross = new group("white", this.instance); var blackcross = new group("black", this.instance); var build = function(group, color, width) { var vertical = new line( group , [0 , 0] , [0 , 50] ); vertical.setname("vertical"); vertical.stroke(width, color); var horizontal = new line( group , [0 , 50] , [50 , 0] ); horizontal.setname("horizontal"); horizontal.stroke(width, color); }; build(whitecross.instance, white, (3 * scale) ); build(blackcross.instance, black, (1 * scale) ); this.instance.position = position; } eyelet.prototype = new shape();
when write
var eyelet = new eyelet(layer2, [10,10]);
i get
group not have constructor
i've ran code through jslint , can't see why isn't working. appreciated.
it turns out fact in adobe illustrator is relevant. renamed group
object mygroup
dan breslau suggested , worked expected. seems illustrator has global group
object causing problem. help.
Comments
Post a Comment