Type.registerNamespace 메서드
업데이트: 2007년 11월
네임스페이스를 만듭니다. 이 멤버는 정적 멤버이며 클래스의 인스턴스를 만들지 않고 호출할 수 있습니다.
Type.registerNamespace(namespacePath)
인수
- namespacePath
등록할 정규화된 네임스페이스를 나타내는 문자열입니다.
예외
예외 형식 |
조건 |
---|---|
(디버그) namespacePath에 잘못된 문자가 포함되어 있는 경우 |
|
(디버그) namespacePath가 올바른 네임스페이스가 아닌 경우 |
설명
registerNamespace 메서드를 사용하면 네임스페이스를 만들 수 있습니다. 네임스페이스는 코드를 구성하는 데 사용할 수 있는 범위 영역입니다. 이는 대규모 프로젝트에서 특히 유용합니다. 네임스페이스를 사용하면 클래스를 그룹화할 수 있습니다. 그러면 각 클래스 이름은 해당 네임스페이스로 한정되므로 고유한 전역 클래스 이름을 만들 수 있습니다.
네임스페이스 내에서 다음과 같은 클래스를 하나 이상 선언할 수 있습니다.
다른 네임스페이스
클래스
인터페이스
열거형
대리자
정규화된 클래스 이름에는 MyNamespace.MyType과 같이 .(도트) 연산자로 구분된 네임스페이스가 포함됩니다. 또한 네임스페이스 이름에는 A–Z 범위에 있는 대/소문자와 0-9 범위에 있는 정수가 포함될 수 있습니다.
예제
다음 예제에서는 registerNamespace 메서드를 사용하여 Samples 네임스페이스를 등록하는 방법을 보여 줍니다.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Sample</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="ScriptManager1">
</asp:ScriptManager>
<script type="text/javascript">
// Register classes to test.
Type.registerNamespace('Samples');
Samples.A = function()
{
// Initialize as a base class.
Samples.A.initializeBase(this);
}
Samples.B = function(){}
Samples.C = function(){}
Samples.A.registerClass('Samples.A');
Samples.B.registerClass('Samples.B', Samples.A);
Samples.C.registerClass('Samples.C');
var isDerived;
isDerived = Samples.B.inheritsFrom(Samples.A);
// Output: "true".
alert(isDerived);
isDerived = Samples.C.inheritsFrom(Samples.A);
// Output: "false".
alert(isDerived);
</script>
</form>
</body>
</html>