자바 스크립트에서 객체에 대해 배우기 위해 테스트 HTML 파일을 작성합니다. 스크립트 태그하나의 함수에서 전역 변수를 선언하고 다른 함수에서 값을 할당하는 방법
을 다음과 같이 코드 제가
<button onclick="initer()"> Click here to test </button>
<div id="id_div1"></div>
문제점 AnotherParentFn.prototype.caller가 initer() 함수 임시 변수로부터 호출 될 때이다 여전히 정의되지 이용해 체내에
<script type="text/javascript">
var obj = new ParentFn();
var obj2 = new AnotherParentFn();
var temp;
function initer()
{
temp = obj.Adding();
obj2.caller();
}
function ParentFn()
{
this.a = 10;
this.b = 20;
}
function AnotherParentFn()
{
this.a = 30;
this.b = 50;
}
AnotherParentFn.prototype.caller = function()
{
var self = this;
temp();
}
ParentFn.prototype.Adding = function()
{
var self = this;
document.getElementById("id_div1").innerHTML = " Method Called and Result of a+b is " + (self.a + self.b);
}
</script>
인 . 코드의 문제점은 무엇입니까 ??
내 작업은 ParentFn.prototype.Adding 함수를 전역 변수에 할당하고 AnotherParentFn.prototype.caller 함수에서 전역 변수를 호출하는 것입니다. 그것을 성취하는 방법?
임시 변수가 이미 전역 변수입니다. –
답을 수락하면 좋을 것입니다. – hifier