2017-05-23 8 views
0

こんにちは私は、firstFunctionからすべてのコンテンツをほとんど継承するsecondFunctionからDRYコード(繰り返しコードではない)を作成しようとしています。ほぼすべてを最初の関数から継承する

これは私が何をしたいの例だろうが、それはDRYではありません。

function firstFunction(){ 
 
\t 
 
    this.arrayObjectsToElastic = ["hello1", "hello2"] 
 
    this.anothervariable1= "anothervariable1" 
 
    this.anothervariable2= "anothervariable2" 
 
    this.targetVariableToRemove = "something" 
 
    return [this.arrayObjectsToElastic] 
 
} 
 

 

 
function secondFunction(){ 
 
\t 
 
    this.arrayObjectsToElastic = ["hello1", "hello2"] 
 
    this.anothervariable1= "anothervariable1" 
 
    this.anothervariable2= "anothervariable2" 
 
    
 
    return [this.arrayObjectsToElastic] 
 
}

したがって、私はfirstFunctionからsecondFunction targetVariableToRemoveに「継承」したくありませんもしそうなら、私が走っている他のいくつかのプロセスでクラッシュすることになるからです。

+0

を興味の絶対に何もしません、このサンプルでは、​​実際に具体的な方法でのお手伝いをするために少しあまりにも抽象的です。しかし、一般的には、関数本体のための「継承」はありません。 – deceze

+0

@deceze私はそれをoopに変換しました、おそらくそれは助けます;) – Defoe

答えて

1

たぶん、あなたのような何かをすることができます:単にローカル変数を宣言するので

function secondFunction(){ 
    return firstFunction().concat(["newContent"]); 
} 
関連する問題