2014-11-27 7 views
0

여기에 질문이 있는데, html5 javascript 코드에 대해 새로운 것을 시도하고 싶습니다. 다른 함수에서 매개 변수를 호출하는 함수를 작성하는 방법. 내가) 함수 시도 (에서 매개 변수를 "원"전화 {, 다른 위치 여기새 함수를 만들고 다른 함수에서 매개 변수를 호출하십시오.

캔버스에 다른 원을 그리 싶은 내 논리의 :

var canvas = ...; 
var ctx = ....;  
x = 0; 
y = 0; 

function try(circle,rect) { 
    (...) 
    circle[0] = .....; //x coordinates 
    circle[1] = .....; //y coordinates 

    rect[0] = .....; 
    rect[1] = .....; 

    ctx.arc(circle[0].circle[1],circle[2],0,Math.PI*2); 
    ctx.fill(); 

    ctx.fillRect(0, 0, rect[0], rect[1]); 
} 

try([x,y,30], [x,y]); 

function callParam() { 
//Here i want to call parameter "circle", 
//to draw another circle in canvas with different position 

//can i put a code like this? : 
anotherCircleX = try.circle[0] +200; 
anotherCircley = try.circle[1] + 100; 
} 
callParam(); 

도움말 및 솔루션과 일부 예 : 저를 가르쳐

답변

1

글로벌 변수에 원 값을 저장하십시오.

var circle_latest = []; 
... 
function try(circle, rect){ 
(...) 
    circle[0] = .....; //x coordinates 
    circle[1] = .....; //y coordinates 
    circle_latest = circle; 
(...) 
} 

function callParam() { 
    anotherCircleX = circle_latest[0] +200; 
    anotherCircley = circle_latest[1] + 100; 
} 
관련 문제