我一直在写一些Adobe Illustrator JavaScripts来改善我的工作流程。最近我一直非常关注OOP,所以我一直在使用对象编写它,并且我认为它有助于保持我的代码清洁且易于修改。不过,我想和你们一起检查一些最佳做法。javascript类应该显式返回什么?
我有一个矩形对象,它创建(三个猜测)...矩形。它看起来像这样
function rectangle(parent, coords, name, guide) {
this.top = coords[0];
this.left = coords[1];
this.width = coords[2];
this.height = coords[3];
this.parent = (parent) ? parent : doc;
var rect = this.parent.pathItems.rectangle(this.top, this.left, this.width, this.height);
rect.name = (name) ? name : "Path";
rect.guides = (guide) ? true : false;
return rect;
}
然而,代码工作正常使用或不去年
return rect
所以我的问题是什么呢
new rectangle(args);
回报,如果我没有明确这么说?
如果我这样做:
var myRectangle = new rectangle(args);
myRectangle.left = -100;
它工作得很好阉我return rect
与否。
非常感谢您的帮助。
您可以通过点击向上箭头来调高我的答案。您应该通过点击我答案旁边的空白复选标记来接受您的问题的答案。 – 2010-10-13 08:46:21
我尝试了upvoting它,但我没有足够的声誉,我害怕。你能接受多个答案吗?我的理解是你等待一段时间,接受最好的一个?你的回答非常好,但我还不知道别人会说些什么。或者我没有得到它? – MrMisterMan 2010-10-13 09:10:27