您好我试图从第二个函数创建DRY代码(不重复代码),该函数继承了firstFunction的所有内容。
这就是我想要的例子,但它不是干的:
function firstFunction(){
this.arrayObjectsToElastic = ["hello1", "hello2"]
this.anothervariable1= "anothervariable1"
this.anothervariable2= "anothervariable2"
this.targetVariableToRemove = "something"
return [this.arrayObjectsToElastic]
}
function secondFunction(){
this.arrayObjectsToElastic = ["hello1", "hello2"]
this.anothervariable1= "anothervariable1"
this.anothervariable2= "anothervariable2"
return [this.arrayObjectsToElastic]
}

因此,我不想继续"继承"在secondFunction中,targetVariableToRemove来自firstFunction,因为如果是这样,它会在我正在运行的其他一些进程中崩溃。
答案 0 :(得分:1)
也许你可以这样做:
function secondFunction(){
return firstFunction().concat(["newContent"]);
}