2017-05-23 1 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] 
 
}

을 따라서, 나는 "상속"하지 않을에서는 secondFunction targetVariableToRemove으로하여 firstFunction에서 왜냐하면 내가 실행중인 다른 프로세스에서 충돌을 일으킬 수 있기 때문입니다.

+0

을 관심이 절대적으로 아무것도하지 않는다,이 샘플은 정말 구체적인 방법으로 당신을 돕기 위해 조금 너무 추상적이다. 그러나 일반적으로 함수 몸체에는 "상속 (inheritance)"과 같은 것이 없다. – deceze

+0

@deceze 나는 이것을 oop으로 변환했다. 아마도 도움이 될 것이다.) – Defoe

답변

1

어쩌면 당신은 같은 것을 수행 할 수 있습니다 단지 지역 변수를 선언하기 때문에

function secondFunction(){ 
    return firstFunction().concat(["newContent"]); 
} 
관련 문제