728x90

그리움으로 말하기엔
아련히 아파오는 기억이
가슴을 짓누르는 슬픔이 된다.
빗줄기에 기억들이 씻겨지는 것 같지만,
사랑이 어디 그리 쉽게 지워질 수 있을까?
그 향기에 베인 추억들은 넓은 대지에 스며,
걷고 또 걷는 발자국마다
깊게 패인 늪처럼
상처받은 마음을 끌어당긴다.
한 순간의 기억이 마치 많은 시간 속을 달리는 열차가 되어
한 없이 길게 놓여진 가슴속을 뒤 흔든다.
아파하며 그리워하는 것이
손발이 찢겨지며 붉은 피를 흘리는 것과 어찌 다르겠는가?
사랑이란 아픔과 기쁨이 될 수 있는 마음인 것을
어찌 맑은 빗줄기에 씻는다하여 씻겨지겠는가?
그리움이란 미련한 기다림인 것을
목놓아 울어본들 그 슬픔이 보여지겠는가?
그리움이 희미해지기 시작하면
아파했던 만큼,
참아 왔던 만큼,
사랑을 기다리는 불빛이 되어
사랑을 가꾸는 커다란 장미꽃핀 정원이 되어
깊게 고인 맑은 호수를 달리는 바람을 따라
맑게 스치는 속삭임이 된다.

728x90

'에세이' 카테고리의 다른 글

마지막 사랑을 남겨야 할 때일지도 모른다.  (0) 2011.06.14
출금길에 들꽃  (0) 2011.06.11
얼만큼 더 가야 할까?  (0) 2011.06.11
슬프고 힘들 때 사랑했던 당신  (0) 2011.06.09
하늘을 사랑한 사람  (0) 2011.06.05
728x90

<%
 '********************************************************
 ' 문서제목 : 사용자 정의 함수
 ' 파일명 : Userfunction.asp
 ' 작성자 : 궉장걸
 ' 작성일 : 2006-11-21
 ' 내역 :
 '********************************************************
 
 Class UserFunction

  '클래스 초기화
  Private Sub Class_Initialize() 
  
  End Sub
  
  '클래스 소멸
  Private Sub Class_Terminate()

  End Sub  

  '******************************************************
  ' 함수 기능 : 문자열 캐릭터로 자르기
  ' Parameter :
  '  - str : 원본 Data
  '  - cutLen : 자를 길이
  '******************************************************
  Public Function cutChar(str, cutLen) 
   If Not(IsEmpty(str)) And Not(IsNull(str)) Then
    Dim strLen, strByte, strPos, char, i, charactor_cut_len
    strByte = 0
    strPos = 0
    strLen = Len(str)    '총 글자수

    for i = 1 to strLen
     char = ""
     char = Asc(Mid(str, i, 1)) '아스키 코드값 읽어오기
     char = Left(char, 1)
     if char = "-" then  '"-"이면 2바이트 문자임
      strByte = strByte + 2
     else
      strByte = strByte + 1
     end if
     strPos = strPos + 1
     if cutLen > 0 then
      if  strByte > cutLen then
       strPos = strPos - 1 '마지막 2바이트 문자처리
       exit for
      end if
     end if
    next

    if cutLen <= 0 then
     charactor_cut_len = strByte
    else
     charactor_cut_len = strPos
    end if

    if (charactor_cut_len < strLen) then
     cutChar = Left(str, charactor_cut_len) & "..."
    else
     cutChar = str
    end If
   Else
    cutChar = str
   End If
  End Function
  
  '******************************************************
  ' 함수 기능 : 비교처리 (CompareNum1 과 CompareNum2 비교 후 RtnStr1, RtnStr2 반환)
  ' Parameter :
  '  - CompareNum1 : 비교 검사할 Data
  '  - CompareNum2 : 비교 검사할 Data
  '  - RtnStr1 : 비교 검사후 True 인 경우 반환할 값
  '  - RtnStr2 : 비교 검사후 False 인 경우 반환할 값
  '******************************************************
  Public Function Return_Val(CompareNum1, CompareNum2, RtnStr1, RtnStr2)
   If Not IsNull(CompareNum1) Then
    If (Cstr(CompareNum1) = Cstr(CompareNum2)) Then
     Return_Val = RtnStr1
    Else
     Return_Val = RtnStr2
    End If
   Else
    Return_Val = RtnStr2
   End If
  End Function

  '******************************************************
  ' 함수 기능 : 날짜 검사 ( 2자리로 변환 )
  ' Parameter :
  '  - ChkDate : 검사할 날짜
  '******************************************************
  Public Function date_check(ChkDate)
   IF len(ChkDate) = 1 Then
    date_check = "0" & ChkDate
   Else      
    date_check = ChkDate
   End If
  End Function

  '******************************************************
  ' 함수 기능 : 월별로 마지막 날짜 반환
  ' Parameter :
  '  - DateMonth : 검사할 월
  '  - DateYear : 검사할 년도
  '******************************************************
  Public Function MonthArray(DateMonth, DateYear)
   Dim MonthDay(12)

   MonthDay(1) = 31
   MonthDay(2) = 28
   If YoonCheck(DateYear) Then MonthDay(2) = 29
   MonthDay(3) = 31
   MonthDay(4) = 30
   MonthDay(5) = 31
   MonthDay(6) = 30
   MonthDay(7) = 31
   MonthDay(8) = 31
   MonthDay(9) = 30
   MonthDay(10) = 31
   MonthDay(11) = 30
   MonthDay(12) = 31

   MonthArray = MonthDay(DateMonth)
  End Function

  '******************************************************
  ' 함수 기능 : 날짜 (윤년) 검사 후 Bool형 반환
  ' Parameter :
  '  - chkYear : 검사할 년도
  '******************************************************
  Public Function YoonCheck(chkYear)
   If chkYear Mod 4 <> 0 Then
    YoonCheck = False
   ElseIf chkYear Mod 100 <> 0 Then
    YoonCheck = True
   ElseIf chkYear Mod 400 <> 0 Then
    YoonCheck = False
   Else
    YoonCheck = True
   End If
  End Function

  '******************************************************
  ' 함수 기능 : 정수값 타입별로 반환
  ' Parameter :
  '  - MinNumber : 최소값
  '  - MaxNumber : 최대값
  '  - StepNumber : step 값(Loop 문에서 사용)
  '  - ObjType : 반환 타입(SelectBox, CheckBox, RadioBox)
  '  - ObjName : Object 명(CheckBox, RadioBox 에서 사용)
  '  - LengChkFlag : 길이체크 여부(date_check 함수 호출)
  '  - CompareFlag : 비교 여부(Return_Val 함수 호출 : True, False)
  '  - CompareNumber : 비교값 (CompareFlag 가 True 인 경우 사용)
  '  - Rtn_CompareTrue : 비교결과가 True인경우 반환값
  '  - Rtn_CompareFalse : 비교결과가 False인경우 반환값f
  '  - StyleStr : 스타일시트 문자열
  '******************************************************
  Public Function IntReturn(MinNumber, MaxNumber, StepNumber, ObjType, ObjName, LengChkFlag, CompareFlag, CompareNumber, Rtn_CompareTrue, Rtn_CompareFalse, StyleStr) 
   Dim Temp_Str, Return_Str, ResultValue
   Dim cnt, Rtn_cnt

   ResultValue = ""

   Select Case UCase(CStr(ObjType))
   Case "SELECT" Temp_Str = "<Option value='@val@' @CompareNumber@>@view@</Option>"
   Case Else Temp_Str = "<input type='@ObjType@' name='@ObjName@' value='@val@' @StyleStr@ @CompareNumber@> @view@"
   End Select

   ' 최소값(MinNumber) 에서 최대값(MaxNumber)까지 Loop
   For cnt = MinNumber To MaxNumber Step StepNumber
    ' 길이 체크여부(2자리로 재정의)
    If LengChkFlag Then
     Rtn_cnt = date_check(cnt)
    Else
     Rtn_cnt = cnt
    End If
    Return_Str = Replace(Temp_Str, "@ObjType@", ObjType)
    Return_Str = Replace(Return_Str, "@ObjName@", ObjName)
    Return_Str = Replace(Return_Str, "@StyleStr@", StyleStr)
    Return_Str = Replace(Return_Str, "@val@", Rtn_cnt)
    Return_Str = Replace(Return_Str, "@view@", Rtn_cnt)
    ' 비교여부
    If CompareFlag Then
     Return_Str = Replace(Return_Str, "@CompareNumber@", Return_Val(Rtn_cnt, CompareNumber, Rtn_CompareTrue, Rtn_CompareFalse))
    Else
     Return_Str = Replace(Return_Str, "@CompareNumber@", "")
    End If
    ResultValue = ResultValue & Return_Str
   Next
   IntReturn = ResultValue
  End Function

  '******************************************************
  ' 함수 기능 : 데이터 부분 반환
  ' Parameter :
  '  - Data : 원본 Data
  '  - Gubun : split()함수에 사용할 구분값
  '  - index : 배열번호
  '******************************************************
  Public Function Rtn_DataSplit(Data, Gubun, index)
   If InStr(Data, Gubun) Then
    tmp_Data = Split(Data, Gubun)
    If UBound(tmp_Data) >= index Then
     Rtn_DataSplit = tmp_Data(index)
    End If
   End If
  End Function

  '******************************************************
  ' 함수 기능 : html 태그 변환
  ' Parameter :
  '  - str : 원본 Data
  '******************************************************
  Public Function HtmlTagChk(str)
   Dim ResultValue
   ResultValue = ""
   If str <> "" Then
    ResultValue = Replace(Replace(Replace(Replace(Trim(str), "&", "&amp;"), "<", "&lt;"), ">", "&gt;"), "'", "''")
    ResultValue = Replace(ResultValue, chr(13)&Chr(10), "<br>")
   End If
   HtmlTagChk = ResultValue
  End Function

  '******************************************************
  ' 함수 기능 : 코드 생성
  ' Parameter :
  '******************************************************
  Public Function getGoodsCode()  
   Randomize  
   getGoodsCode = Chr(Int(Rnd()*26) + 65)& Chr(Int(Rnd()*26) + 65) & Left(Replace(Now, "-", ""), 8) & Hour(Now) & Chr(Int(Rnd()*20) + 65)
  End Function

  '******************************************************
  ' 함수 기능 : 주문코드 생성
  ' Parameter :
  '******************************************************
  Public Function getOrderCode2()
   Randomize  
   getOrderCode2 = Left(Replace(Now, "-", ""), 8) & Hour(Now) & Minute(Now) & Second(Now) & Chr(Int(Rnd()*20) + 65) & Chr(Int(Rnd()*26) + 65)
  End Function

 End Class
%>

728x90

'프로그래밍 > asp' 카테고리의 다른 글

ASP에서 CSV 파일 생성하기  (0) 2011.08.03
ON Error Resume Next  (0) 2011.06.24
ASP 오류 'ASP 0115'  (0) 2011.06.15
asp 함수 정리  (0) 2011.06.08
DateAdd를 이용한 날짜 계산  (0) 2011.06.01
728x90
01.<%
02.    ' 금일 날짜 표현방법
03.    Response.write Right("0000"&Year(date),4) &"-"& Right("00"&Month(date),2) &"-"&Right("00"&Day(date),2)
04.  
05.    ' 1년전 날짜 구하기
06.    Tdate = DateAdd("m", -12 DateValue(now))
07.    Response.write Tdate &"<BR>"
08.  
09.  
10.    ' 7일후 날짜 구하기
11.    Tdate = DateAdd("d", 7 DateValue(now))
12.    ' or
13.    Tdate = dateadd("d", 7, Now())
14.    Response.write Tdate &"<BR>"
15.   
16.  
17.    '순수히 날짜만 구할려면 MID 함수 사용
18.    Response.write MID(Tdate,1,10)
19.  
20.  
21.    '"-" 문자열을 제거할려면 replace 함수를 사용하면 됩니다.
22.    Response.write replace("문자열", "-", "")
23.%>

728x90

'프로그래밍 > asp' 카테고리의 다른 글

ASP에서 CSV 파일 생성하기  (0) 2011.08.03
ON Error Resume Next  (0) 2011.06.24
ASP 오류 'ASP 0115'  (0) 2011.06.15
asp 함수 정리  (0) 2011.06.08
asp 함수  (0) 2011.06.01
728x90

728x90

'웃음찾기' 카테고리의 다른 글

이것 또한 지나가리라.  (0) 2011.07.05
토요일,일요일,월요일 표정.  (0) 2011.06.11
존버정신  (0) 2011.06.09
최홍만 착시효과  (0) 2011.06.08
주차금지  (2) 2011.05.19
728x90


1. for문 안의 배열 iterate
 
 Example:
 var myArray = [ “a”, “b”, “c” ];
 var totalElements = myArray.length;
 for (var i = 0; i < totalElements; i++) {
 console.log(myArray[i]);
 }


 Solution: always use regular for loops to iterate arrays.
 var myArray = [ “a”, “b”, “c” ];
 for (var i=0; i<myArray.length; i++) {
  console.log(myArray[i]);
 }
 
 << myArray 에 대한 간섭으로 인해 잘못된 정보를 참조할 수 있다고 하는 내용인데요...
    이글에 대한 많은 분들이 댓글 이슈를 달아주시기도 한 내용입니다.
 그럼 이슈가 무엇이였냐면요... 위 Example 에 대한 예시가 잘못되었다는 것이죠
 Example :
  for (var el in myArray){}
 Solution :
  for(var i = 0, iMax = myArray.length; i < iMax; i++){}
 이런 식으로 했어야 하였다는 이슈가 있더군요.
 
2. 배열 정의
 Example:
 var myArray = new Array(10);
 Solution: Use literal notation to initialize arrays. Do not predefine array length.
 var myArray = [];
 
 << 문제점 2개를 이야기 하는데요
      var a = new Array(10); // 빈 item 에 접근으로 인해 undefined 발생
  var a = {"","","","",....,""}; // 속도가 느린문제
  이런 문제를 앉고 있다고 하네요 >>
 
 
3. Undefined properties
 Example:
 var myObject = {
  someProperty: “value”,
  someOtherProperty: undefined
 }
 Solution: if you want to explicitly declare a uninitialized properties inside an object, mark them as null
 var myObject = {
  someProperty: “value”,
  someOtherProperty: null
 }
 
 << object 에 없는 값과 있으나 undefined 로 정의한 값을 구분할 수 없다는 이슈였습니다.
 typeof myObject['someOtherProperty'] // undefined
 typeof myObject['unknownProperty'] // undefined   >>
 


4. 클로저 오용
 Example:
 function(a, b, c) {
  var d = 10;
  var element = document.getElementById(‘myID’);
  element.onclick = (function(a, b, c, d) {
   return function() {
    alert (a + b + c + d);
   }
  })(a, b, c, d);
 }
 Solution: use closures to simplify your code
 function (a, b, c) {
  var d = 10;
  var element = document.getElementById(‘myID’);
  element.onclick = function() {
   //a, b, and c come from the outer function arguments.
   //d come from the outer function variable declarations.
   //and all of them are in my closure
   alert (a + b + c + d);
  };
 }
 
 << 변수에 대한 접근 범위를 몰라 중복해서 불필요한 파라미터를 정의하는 것을 말합니다. >>
 
5. loop 안의 클로져
 Example:
 var elements = document.getElementByTagName(‘div’);
 for (var i = 0; i<elements.length; i++) {
  elements[i].onclick = function() {
   alert(“Div number “ + i);
  }
 }
 Solution: use a second function to pass the correct value.
 var elements = document.getElementsByTagName(‘div’);
 for (var i = 0; i<elements.length; i++) {
  elements[i].onclick = (function(idx) { //Outer function
   return function() { //Inner function
    alert(“Div number “ + idx);
   }
  })(i);
 }


 << 내부 클로져의 경우 최종값 i 값을 참조한다는 문제였습니다. >>
 
6. DOM 으로인한 메모리 누수
 Example:
 function attachEvents() {
  var element = document.getElementById(‘myID’);
  element.onclick = function() {
   alert(“Element clicked”);
  }
 };
 attachEvents();
 Solution: avoid those closures or undo the circular reference inside the function
 function attachEvents() {
  var element = document.getElementById(‘myID’);
  element.onclick = function() {
   //Remove element, so function can be collected by GC
   delete element;
   alert(“Element clicked”);
  }
 };
 attachEvents();
 
 << 요소에 function이 참조로 걸려 해제가 되지 않는 문제를 다루고 있습니다. >>


7. float 과 integer의 구분
 Example:
 var myNumber = 3.5;
 var myResult = 3.5 + 1.0; //We use .0 to keep the result as float
 Solution: don’t use decimals to “convert” numbers to floats.
 var myNumber = 3.5;
 var myResult = 3.5 + 1; //Result is 4.5, as expected
 
 << 자바스크립트 float 과 integer 구분이 없습니다. 모두 float 입니다. >>
 
8. with() 사용
 Example:
 team.attackers.myWarrior = { attack: 1, speed: 3, magic: 5};
 with (team.attackers.myWarrior){
  console.log ( “Your warrior power is ” + (attack * speed));
 }
 Solution: don’t use with() for shortcuts. Only for context injection when you really need it.
 team.attackers.myWarrior = { attack: 1, speed: 3, magic: 5};
 var sc = team.attackers.myWarrior;
 console.log(“Your warrior power is ” + (sc.attack * sc.speed));


 << with() 는 특별한 경우가 아니면 사용하지 말라는 내용입니다. 이유는 느리기 때문입니다. >>
 
9. 문자 조합을 이용한 setTimeout/setInterval
 Example:
 function log1() { console.log(document.location); }
 function log2(arg) { console.log(arg); }
 var myValue = “test”;
 setTimeout(“log1()”, 100);
 setTimeout(“log2(” + myValue + “)”, 200);
 Solution: never use strings for setTimeout()or setInterval()
 function log1() { console.log(document.location); }
 function log2(arg) { console.log(arg); }
 var myValue = “test”;
 setTimeout(log1, 100); //Reference to a function
 setTimeout(function(){ //Get arg value using closures
  log2(arg);
 }, 200);
 
 << 스트링 조합을 사용할 경우 웹브라우저 엔진이 새로운 function 을 만들때 매우 느려지기때문에
    이렇게 사용하지 말라고 말합니다. >>
 
10. 무거운 funcation에 대한 setInterval() 사용
 Example:
 function domOperations() {
  //Heavy DOM operations, takes about 300ms
 }
 setInterval(domOperations, 200);
 Solution: avoid setInterval(), use setTimeout()
 function domOperations() {
  //Heavy DOM operations, takes about 300ms
  //After all the job is done, set another timeout for 200 ms
  setTimeout(domOperations, 200);
 }
 setTimeout(domOperations, 200);


 <<  자바 스크립트 엔진은  대기열에 이미 다른 실행이있다면 다음 실행 대기열에 추가합니다.
  이럴경우 function 을 건너뛰거나 동시에 실행될 소지가 발생합니다. >>
 >>
11. this 의 오용
 - 예로 표현하기 어려움.
 * Regular function: myFunction(‘arg1’);
 this points to the global object, wich is window for all browers.
 * Method: someObject.myFunction(‘arg1’);
 this points to object before the dot, someObject in this case.
 * Constructor: var something = new myFunction(‘arg1’);
 this points to an empty Object.
 * Using call()/apply(): myFunction.call(someObject, ‘arg1’);
 this points to the object passed as first argument.
 
 << 여기에 대해서는 궁금하네요...접근에 대한 이슈같아 보입니다. >>
 
12. eval() 을 이용한 dynamic properties 접근
 Example:
 var myObject = { p1: 1, p2: 2, p3: 3};
 var i = 2;
 var myResult = eval(‘myObject.p’+i);
 Solution: use square bracket notation instead of eval()
 var myObject = { p1: 1, p2: 2, p3: 3};
 var i = 2;
 var myResult = myObject[“p”+i];
 
 << eval() 대신에 배열을 이용해서 접근하라는 말입니다. >>
 
13. undefined 를 사용하는 변수
 Example:
 if ( myVar === undefined ) {
  //Do something
 }
 Solution: use typeof when checking for undefined.
 if ( typeof myVar === “undefined” ) {
  //Do something
 }
 
 << undefined 확인하기위해서는 typeof 를 사용하라는 것입니다. >>
 


 

728x90

'프로그래밍 > 자바스크립트' 카테고리의 다른 글

quick menu 바  (0) 2013.07.19
javascript 브라우저 종류  (0) 2012.11.23
자주 쓰이는 JQuery Ajax 예제  (0) 2011.08.02
jQuery 요약  (0) 2011.08.02
자바스크립트 팁  (0) 2011.05.20
728x90

* 지역변수는 함수 전체에서 정의되어 있다. var 문이 실행되고 나서야 실제로 초기화가 이루어진다.
* 모든 객체는 객체를 초기화하는데 사용되는 생성자 함수인 constuctor 프로퍼티를 갖는다.
* 리터럴 객체 혹은 리터럴 배열 생성방법: var obj = {} , var arr = [] 이다. 생성자를 사용 호출시 new() 사용한다.

함수 전역 변수
function square(x) { return x * x; }
var a = square(4);  // a에는 숫자 16이 저장된다.
var b = square;      // 이제 b는 square 같은 함수를 가르킨다.
var c = b(5) ;         // c에는 숫자 25가 저장된다.

var o = new Object;
o.square = function(x){ return x * x; } // 함수 리터럴
y = o.square(16);  // y에는 256이 저장된다.

var a = new Array(3); 
a[0] = function(x) { return x * x;}
a[1] = 20;
a[2] = a[0](a[1]); // a[2]에는 400이 저장된다.


) call()메서드
call() : 함수 f()에 두 숫자를 전달하고 이 함수를 마치 객체의 o의 메서드인 것처럼 호출하려 한 다면 다음과 같은
 코드를 작성할 수 있다.
f.call(o, 1, 2);
이 표현은 다음의 코드와 유사하다.
o.m = f;
o.m(1,2);
delete o.m;

) 네임스페이스로서의 호출 객체
function init(){
// 코드는 여기에 넣는다.
// 선언된 모든 변수는 전역 네임스페이스를 어지럽히는 대신
// 호출 객체의 프로퍼티가 된다.
}
init();  // 함수를 호출하는 것을 잊어서는 안된다.

* 익명의 함수를 정의하고 호출하는 단일 표현식을 사용할 수 있다.
(function(){  // 이 함수는 이름이 없다.
// 코드는 여기에 넣는다.
// 선언된 모든 변수는 전역 네임스페이스를 어지럽히는 대신 
// 호출객체의 프로퍼티가 된다.
})();  // 함수 리터럴을 종결하고 이를 지금 호출한다.

* 자바스크립트에서 함수는 다른 모든 값과 마찬가지로 데이터다. 따라서 함수는 다른 함수에 의해 반환될수 있고 객체에 프로
   퍼티로 할당될 수도 있으며, 또한 배열 등에 저장될 수도 있다.

* 자바스크립트의 객체는 자신의 프로토타입에 있는 프로퍼티들을 상속받는다.

// 생성자 함수는 각 인스턴스의 프로퍼티가 다른 값이 되도록 초기화시킨다.
function Rectangle(w, h){
 this.width = w;
 this.height = h;
}
// 프로토타입 객체는 각 인스턴스들이 공유해야 하는 프로퍼티나 메서드를 정의한다.
// 생각) JAVA의 static 역할을 말하는 거 같다.
Rectongle.prototype.area = function(){ return this.width * this.height; }

생성자는 객체들의 클래스를 위한 이름을 정의하고 , width나 height와 같은 인스턴스마다 다를 수 있는 프로퍼티의 값을 초기화시킨다. 그리고 프로토타입 객체는 생성자와 연결되며, 이 생성자를 통해 생성되는 객체들은 프로토타입이 가진 프로터티들을 똑같이 상속받는다. 이 말은 프로토타입 객체가 메서드나 상수 같은 프로퍼티들을 위치시키기에 좋은 곳임을 의미한다.

프로토타입의 프로퍼티들은 클래스의 모든 객체가 공유하기 때문에, 모든 객체가 같이 사용하는 프로퍼티들을 정의해놓는 것

// 마지막 문자가 변수 c의 값과 같으면 참을 반환한다.
String.prototype.endWith = function(c){
  return ( c == this.charAt(this.length-1) );
}
var message = "hello world";
message.endWith('h') // 거짓을 반환
message.endWith('d') // 참을 반환

** 예제 **

//생성자 함수를 정의
function Circle(radius){
// r은 인스턴스 프로퍼티이며, 생성자 안에서 저의되고 초기화된다.
this.r = radius;
}

// Circle.PI는 클래스 프로퍼티다. 이것은 생성자 함수의 프로퍼티이다.
Circle.PI = 3.14159;

// 여기에는 원의 넓이를 계산하기 위한 인스턴스 메서드가 정의되어 있다.
Circle.prototype.area = function() { return Circle.PI * this.r * this.r; };

// 이 클래스 메서드는 Circle의 두 객체들을 받아서 더 큰 반지름을 가진 것을 반환한다.
Circle.max = function(a, b){
if(a.r > b.r) return a;
else return b;
};

// 여기에 나타나있는 코드는 위에서 정의된 필드를 사용한다.
var c = new Circle(1.0);   // Circle 클래스의 인스턴스를 하나 만든다.
c.r = 2.2;            //인스턴 프로퍼티 r의 값을 지정한다.
var a = c.area();   // 인스턴스 메서드인 area()를 호출한다.
var x = Math.exp(Circle.PI);    // 클래스 프로퍼티인 PI를 사용하여 계산을 한다.
var d = new Circle(1.2);     // 다른 Circle 인스턴스를 만든다.
var bigger = Circle.max(c, b); //클래스의 메서드 max()를 사용한다.

** 예제 끝 **

* typeof는 기본 타입을 객체와 구별하는 데 가장 유용하게 사용 할 수 있다. 
   typeof undefined는 'undefined' 지만 typeof null은 'object'이다.
   모든 배열은 객체이기 때문에 배열의 타입도 'object'다. 
   함수는 객체이긴 하지만 타입은 'function'이다.

* 어떤 값이 기본 타입이나 함수가 아니라 객체라고 판단하면 이에 관련하여 정보를 얻기위해 instanceof연산자를 사용한다.
   x instanceof Array
   객체 o에 대해서 instaceof Object는 항상 true이다. 
   instanceof는 함수에 대해서도 작동하며 아래의 모든 표현은 함수 f에 대해 true다.
    typeof f == "function"
    f instanceof Function
    f instanceof Object

var d = new Date();   // Date 객체, Date는 Object를 확장한다.
var isobject = d instanceof Object; // true 평가한다.
var realobject = d.constructor == Object; // false로 평가한다.

** 13장 웹  브라우저와 자바스크립트 **

* 클라이언트 자바스크립트에서는 Document 객체가 HTML 문서를 나타낸다.
* Window 객체는브라우저 창 또는 프레임을 나타낸다. 
   Window 객체가 클라이언트 측 프로그래밍에서 전역 객체역할을 담당하고 있다.

* 여러 개의 창(또는 프레임)을 사용해서 애플리케이션을 작성할 수 있는데, 애플리케이션에 속한 각 창은 고유한 Window 객체를 가지며, 클라이언트 측 자바스크립트 코드의 고유한 컨텍스트를 정의한다.





 ** 비공식 스크립트 어트리뷰트 **
MS는 오직 익스플러에서만 작동하며 event와 for 어트리뷰트를 사용한다. << 사용하지 말자 >>

** onload
onload 이벤트 처리기는 모든 문서의 파싱이 끝나고 모든 스크립트가 실행된 후 그리고 모든 보조내용( 이미지 같은 것들 )
 onload 이벤트를 방생시켜 Window객체에 onload 이벤트 처리기가로 등록된 모든 자바스크립트 코드를 실행한다.
onload 처리기가 구동되는 때는 모든 문서의 읽기 작업과 파싱 작업이 완전히 끝난 후이기 때문에 모든 문서 엘리먼트는 
자바스크립트를 사용하여 조작할 수 있다.

** onunload 이벤트 처리기
사용자가 웹 페이지를 떠나 다른 곳으로 이동할 때 브라우저는 현제 페이지에 대한 자바스크립트 코드의 마지막 실행 기회를
onunload 이벤트 처리기를 구동한다.

* 클라이언트 쓰레다는 단일 쓰레드다. 싱글 쓰레드
 
* URL에서 전달인자 추출하기 예
function getArgs(){
 var args = new Object(); 
 var query = location.search.substring(1);
 var pairs = query.split("&");
 for(var i=0; i<pairs.length; i++){
  var pos = pairs[i].indexOf("=");
  if(pos == -1) continue;
  var argname = pairs[i].subtring(0, pos); // 키값을 추출한다.
  var value = pairs[i].substring(pos+1); //값을 추출한다.
  var = decodeURIComponent(value); // 필요하다면 디코딩을 수행한다.
  args[argname] = value;  // 객체 프로퍼티로 저장한다.

 }
 return args;
}

** Document 객체 이름 짓기 **

<form name="f1"><input tpye="button" value="Push Me"></form>
document.forms[0]     // 문서 내의 위치를 통해 참조 
document.forms.f1       // 프로퍼티로 이름을 통해 폼 참조
document.forms["f1"]   //배열 인텍스로 이름을 통해 참조
  document.f1

<form nam="shipping">
 ..
 <input type="text" name="zipcode">
..
</form>
doument.shipping.zipcode

만약  name 어트리뷰트가 모두 'n' 이라는 똑같은 이름을 사용한다면 
 document.n 프로퍼티는 두 원소에 대한 참조를 가지는 배열이 된다.

<form name="myform" onsumit="return validateform();">...</form>
document.myform.onsubmit = validateform;



HTML 문서의 트리 표현


* '트리라는 표현은 가족 구조를 표현하는 트리에서 빌려온 것이다.
한 노드의 바로 위에 있는 노드는 아래에 있는 노드의 부보(parent)다.
다른 노드의 바로 한 레벨 밑에 있는 노드는 위에 있는 노드의 자식(children)이다.
같은 부모를 가졌으며 같은 레벨에 있는 노드들을 형제(sibling)이다.
어떤 노드의 아래에 있는 모든 노드(레벨의 상관없이)는 위에 있는 노드의 자손(descendant)이다.
부모와 조부모를 비롯하여 어떤 노드의 위에 있는 모든 노드는 아래에 있는 노드이 조상(ancestor)이다.

* 문서의 노드 순회 예
function countTags(n){
 var numtags = 0;
 if(n.nodeType == 1 /*Node.ELEMENT_NODE*/)
  numtags++;
  var children = n.childNodes;
  for(var i=0; i<children.length; i++){
   numtags += countTags(childdren[i]);
  }
  return numtags;
}

<body onload="alert('this document has '+ countTags(document) +' tags')">

*
document.getElementByTagName("body")[0];
var tables = document.getElementByTagName("table");
alert("This document contains" + tables.length+ " tables");

var myParagraph = document.getElemetByTagName("p")[3];  //효율적이 못하다.

<p id="specialParagraph" />
var myParagraph = docment.getElementById("specialParagraph");

function id(x){
 if(typeof x == "string") return document.getElementById(x);
   return x;
}

var headLine = document.getElementById("headLine");
headLine.setAttribute("align", "center");

var headLine = document.getElementById("headLine");
headLine.align = "center";


** 이벤트와 이벤트 처리 **

<input type="button" value="Click Here" onclick="alert(this.onclick 또는 typeof this.onclick); ">
자바스크립트를 통해 접근하면 이벤트 처리기 프로퍼티는 함수가 된다. 
이벤트 처리기에서 this 키워드는 이벤트가 발생한 객체를 참조한다. this.value -> Click Here 출력되는 걸 보면 Button엘리먼트를 참조 하는거 같다.

*--
<form name="f1">
 <input type="button" name="b1" value="Pree Me" />
</form>

document.f1.b1.onclick = function(){
alert("Thanks");
}
*--
function plead(){
document.f1.b1.value += ", please!";
}
document.f1.b1.onmouseover = plead;
*--

( HTML 어트리뷰트와 자바스크립트 프로퍼티에 상관없이 ) 이벤트 처리기는 대부분 반환값을 사용하여 이벤트 특성을 나타냄
<form name="f1" action="www.naver.com" 
          onsubmit="if(this.elements[0].value.length==0) return false;">
<form name="f1" action="www.naver.com" 
          onsubmit="if(this.elements['namef'].value.length==0) return false;">
<form name="f1" action="www.naver.com" 
          onsubmit="if(this.namef.value.length==0) return false;">

<form name="f1" action="www.naver.com" onsubmit="if(new String(this.namef.value).trim().length==0) return false;">
 <input type="text"  name="namef" />
 <input type="submit" value="go" />

</form>
*--

button.onclick = o.mymethod;
이 문장은 button.onclick이 o.mymethod 함수를 참조하게 만든다. mymethod함수는 이제 o와 button둘 모두의 메서드다.
this 키워드는 이제 o가 아닌 Button객체를 참조한다.

*--

<form >

<!-- 이벤트 처리기에서 this는 이벤트의 대상 엘리먼트를 참조한다. -->
<!-- 따라서 폼 내의 이웃 엘리먼트를 다음과 같이 참조할 수 있다. -->
<input id="b1" type="button" value="button1" onclick="alert(this.form.b2.value);">
<!-- 대상 엘리먼트도 유효 범위 체인 안에 있기 때문에 this를 생략할수 있다. -->
<input id="b2" type="button" value="button2" onclick="alert(form.b1.value);">
<!-- <form>도 유효 범위에 있기 때문에 생략 가능 -->
<input id="b3" type="button" value="button3" onclick="alert(b4.value);">
<!-- Document 객체는 유효 범위 체인 상에 있기 때문에 이 객체의 메서드는  -->
<!-- Document document를 앞에 붙이지 않고도 사용 할 수 있다.  -->
<!-- 하지만 좋은 습관은 아니다. -->
<input id="b4" type="button" value="button4" onclick="alert(getElementById('b3').value);">

</form>

*--

함수는 자신이 호출된 곳이 아니라 자신이 정의된 곳의 유효범위를 사용하여 실행됨을 기억해야 된다.

이벤트 처리기 유효 범위에 대한 모든 설명은 이벤트 처리기를 html 어트리뷰트로 저의하는 경우에만 해당된다는 사실을 
명심해라 한다.

** 폼( Form ) 객체 **

Form객체는 Document객체의 프로퍼티 중 하나인 forms[]배열의 원소를 통해 접근할 수 있다.
마지막 폼에 접근 하는 방법 : document.forms[document.forms.length-1]

현재 창에서 문서의 두 번째 폼에 속한 세 번째 엘리먼트를 참조하려면 
생각)elements는 해당 폼 객체 안에 있는 여러가지 input, button, checkbox...  뜻하는 거 같다.
document.forms[1].elements[2]

*
onsubmit 처리기는 순수하게 Submit 버튼을 클릭하는 것에 의해서만 구동됨을 명심해라.
*
모든 폼 엘리먼트에는 자신이 폼을 참조하는 form프로퍼티가 있다.
폼 엘리먼트의 이벤트 처리기에서는 this.form으로 Form객체를 참조할 수 있다.
형제 관계에 있는 x라는 폼 엘리먼트를 참조하려면 this.form.x 라고 한면 된다.
*
checkbox와 radio 엘리먼트는 토글 버튼이다. ( 선택아니면 해제 )
이름이 같은 토글엘리먼트를 배열로 받기 위해
document.erverything.extras
개별 참조하려면 
document.erverything.extras[0]

radio와 checkbox 엘리먼트에는 공통적으로 checked라는 프로퍼티가 있다.
페이지가 처음 로딩되었을 때 해당 엘리먼트가 선택되어 있을 것인지 여부를 나타낸다. defaultChecked 
 프로퍼티는 HTML checked 어트리뷰트에 해당하는 겂을 가지는 불리언 프로퍼티이다.

select 엘리먼트 속에 options[]배열 안에 저장된 Option 객체들을 표현한다.
select-multiple(다중 선택 가능) 일때는 selectIndex 프로퍼티만으로는 현재 선택되어 있는 옵션들을 모두 표현하기 충분치 않다. 이 경우 선택된 것을 판별하기 위해 options[]배열 안에 속한 모든 엘리먼트에 대한 loop문을 이용해 Option객체마다 
selected프로퍼티의 값을 확인해야 한다.
그 외에 text프로퍼티를 이용해 텍스트를 변경. 이와 더블어 value프러퍼티 역시 읽고/쓰기가 가능한 문자열이다. 웹서버로 전달할 문자를 지정한다.

다음과 같이 하면 이 엘리먼트에 속한 모든 옵션들을 제거 할 수 있다.
document.addressF.countryS.options.length = 0; // 모든 옵션들을 제거 

// Select 엘리먼트에서 하나의 Option 객체를 제거한다.
// 기존에 option[11]에 있던 옵션은 option[10]으로 이동한다.
document.addressF.countryS.options[10] = null;
728x90

'프로그래밍 > 자바스크립트' 카테고리의 다른 글

quick menu 바  (0) 2013.07.19
javascript 브라우저 종류  (0) 2012.11.23
자주 쓰이는 JQuery Ajax 예제  (0) 2011.08.02
jQuery 요약  (0) 2011.08.02
자바스크립트 실수 모음  (0) 2011.05.20
728x90
자전거도 주차금지 스티커를 붙이네요.


728x90

'웃음찾기' 카테고리의 다른 글

이것 또한 지나가리라.  (0) 2011.07.05
토요일,일요일,월요일 표정.  (0) 2011.06.11
존버정신  (0) 2011.06.09
최홍만 착시효과  (0) 2011.06.08
임재범과 김연우의 차이  (0) 2011.05.26

+ Recent posts