2012-09-17 38 views
0

下面我有以下代碼:應用功能將多個對象

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)); 

謝謝!

+0

如果是這樣'$(this.resize2.intrface,this.resize2.core)'? – apsillers

+0

這是正確的。我編輯了代碼。 (這不是它不工作的原因) –

回答

0

這是關於一些重複的代碼重構。

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]); 
+0

這給出了以下錯誤: 未捕獲TypeError:無法讀取undefined raphael-min.js的屬性'transform':8 a._extractTransform raphael-min.js: 8 A.transform聖拉斐爾-min.js:8 變換指數:224 mover2指數:233 ķ聖拉斐爾-min.js:8 拉斐爾-min.js:8 ˚F –