블로그 이미지
안녕1999

카테고리

전체 (3067)
자바스크립트 (20)
안드로이드 (14)
WebGL (4)
변비 (17)
정치,경제 (35)
C언어,ARM (162)
컴퓨터(PC, Note Book, 윈.. (41)
전자회로, PCB (27)
유머,안웃긴,GIF,동영상 (118)
국부론60 (71)
모듈(PCB) (3)
건강 (2)
FreeCAD (25)
PADS (43)
퇴직,퇴사,구직,취업 활동 (3)
C# (86)
엑셀 (8)
워드 (0)
LabView (6)
레고 (30)
FPGA (0)
Total
Today
Yesterday

달력

« » 2024.5
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

공지사항

최근에 올라온 글

//document.body.onload등을 대체할 수는 없다.
function html_body_add_java_script(text)
{
	var script=document.createElement('script');
	script.innerHTML=text;
	document.body.appendChild(script);
	return script;
}

var test_script=
"var my_cnt=0;"+
"function test3()"+
"{"+
"	console.log('function test3()',my_cnt);"+
"	my_cnt++;"+
"}"+
"function my_script_onload()"+
"{"+
"	console.log('my_script_onload()');"+
"	setInterval(test3,1000);"+
"}"+
"my_script_onload();"+
"";
html_body_add_java_script(test_script);


Posted by 안녕1999
, |

html문서에 아래와 같이 자바스크립트 파일을 추가하면,

<script src="xxx.j"></script>

웹브라우져는 모든 파일을 로딩하고, 파싱한다.
따라서, 각 스크립트파일간 함수 의존관계 체크는 모든 스크립트 파일이 로딩된 이후에 처리된다.

그러나, include함수를 작성하여, 필요시마다 include할 경우,
해당 스크립트에서 사용하는 함수가 없을 경우, 에러처리된다.
따라서, include 순서가 중요해진다.

//로드되기전에, 다른 파일에 있는 함수를 참조할 경우, 에러발생(html에 스크립트파일로 추가하는 경우엔, 모두 로딩되고나서 실행되므로 에러 발생없음)

var include_file_cnt=0;

function include(file)

{

var script=document.createElement('script');

script.src=file;

include_file_cnt++;

script.onload=function()

{

console.log("include(",file,")");

include_file_cnt--;

if(include_file_cnt==0)

{

main();

}

}

document.body.appendChild(script);

//console.log("include",file);

return script;

}

include("hxxx.j");

include("wxxx.j");


Posted by 안녕1999
, |

최근에 달린 댓글

글 보관함