Javascript 将函数应用于多个对象
我有以下代码:Javascript 将函数应用于多个对象,javascript,Javascript,我有以下代码: this.resize2.intrface.transform(Raphael.format("t{0},{1},S{2},{3},{4},{5}{6}", this.resize2.intrface.ox, this.resize2.intrface.oy,
this.resize2.intrface.transform(Raphael.format("t{0},{1},S{2},{3},{4},{5}{6}",
this.resize2.intrface.ox,
this.resize2.intrface.oy,
xmove,
ymove,
this.resize2.bbx,
this.resize2.bby,
this.resize2.intrface.scale));
this.resize2.core.transform(Raphael.format("t{0},{1},S{2},{3},{4},{5}{6}",
this.resize2.intrface.ox,
this.resize2.intrface.oy,
xmove,
ymove,
this.resize2.bbx,
this.resize2.bby,
this.resize2.intrface.scale));
我想将变换函数应用于一行中的两个对象。这可能吗?要了解我打算做什么,请参见以下(不起作用)示例:
$(this.resize2.intrface, this.resize2.core).transform(Raphael.format("t{0},{1},S{2},{3},{4},{5}{6}",
this.resize2.intrface.ox,
this.resize2.intrface.oy,
xmove,
ymove,
this.resize2.bbx,
this.resize2.bby,
this.resize2.intrface.scale));
谢谢 这是关于一些重复的代码重构
function transform(factoryMethod) {
factoryMethod(Raphael.format("t{0},{1},S{2},{3},{4},{5}{6}",
this.resize2.intrface.ox,
this.resize2.intrface.oy,
xmove,
ymove,
this.resize2.bbx,
this.resize2.bby,
this.resize2.intrface.scale));
}
使用此命令调用:
transform.apply(this, [this.resize2.intrface.transform]);
transform.apply(this, [this.resize2.core.transform]);
应该是
$(this.resize2.intrface,this.resize2.core)
?这是正确的。我已经编辑了代码。(顺便说一句,这不是它不起作用的原因)这会产生以下错误:未捕获类型错误:无法读取未定义raphael-min.js:8 a.的属性“transform”。_extractTransformRaphael-min.js:8 a.transform raphael-min.js:8转换索引:224 mover2索引:233 k raphael-min.js:8 bYraphael-min.js:8楼