2012-05-24 5 views
0

어떻게 제대로

는 는

function Allocate() 
{ 
    this.Name = $("allocateName"); 
    this.AddAllocation = $("addAllocation"); 
    this.setCustom= $("setCustom"); 
} 
... some other initializations here 
Allocate.prototype.EnableAllocations = function() { 

this.enableAllAlloactions(); 
this.setCustomAllocations(); 
} 

이이 형식에 자바 스크립트가 우선이다

내가이 시나리오에서 너무 잘 이해하지 못하는 두 가지가 있습니다

Page.ClientScript에서 함수를 호출하는 자바 스크립트에서 이런 종류의 클래스가 있습니까? 이 파일은 Allocate.js 파일에 있습니다.

내 질문은 다음과 같습니다 : 나는 그렇게 할 것입니다 방법 Page.ClientScript.RegisterClientScriptBlock(...);에서 EnableAllocations를 호출했다면

?

답변

0

Allocate 개체를 인스턴스화하고 해당 EnableAllocations 함수를 호출해야합니다.

var alloc = new Allocate(); 
    alloc.EnableAllocations; 

그래서 그쪽 코드 문자열을 생성하고 다음과 같이 사용하여 전달할 수 있습니다

Page.ClientScript.RegisterClientScriptBlock("key", 
    "var alloc = new Allocate();alloc.EnableAllocations;"); 
  • 참고 :. 당신은 열쇠로 this.GetType()하면 FullName을 사용할 수 있습니다. 다른 스크립트에 대해 동일한 키를 사용해서는 안됩니다.

이 메서드는 더 이상 사용되지 않습니다. 대신 ClientScriptManager.RegisterClientScriptBlock 방법을 사용하십시오 (사용중인 프레임 워크의 버전에 따라 다름).

마지막으로 어떤 라이브러리를 사용하고 있는지 알 수 없지만 $()은 일부 라이브러리에서 제공됩니다. 따라서 해당 라이브러리에 대한 의존성이 있으며, allocateName, addAllocation 등등에도 의존합니다.