본문 바로가기

# PRIVATE

WEB 11,18

p266 Data 객체의 속성과 메소드

prototype : Data 객체에 속성 부여(원하는 filed를 추가할 수 있다. ) = JAVA에서는 ”속성”으로 用
ex)  Array.prototype.comment = null  // 새로운 prototype 속성에 comment변수 초기값 null 할당
cmment 타입을 추가하고 싶어서, prototype.comment로 해서, Array가 갖고 있는 맴버변수인냥, 사용한다.

*get() 계열 :  값을 가져온다.
getYear() : 년도(2개의 숫자로 1970년 이후의 년도를 표시)
getMonth() : 월(0=1월, 1=2월, 2=3월로 표시)
getData() : 일(1에서 31의 정수로 표시)
getDay() :
getTime() : 1970. 1.1일 0시 이후의 시간을 ms(1000분의 1초)로 표시.

* set() 계열 : 값을 집어넣는다.

class A{
private int a; (class A{} 안에서만 사용가능하다.)
void setA(int a);
this a = a +10; (값을 10을 더해서 값을 리턴)

int getA(){
return a;

}

}


A.a = new A();
a.a = 10;
(이런식으로 사용하지 않는다- 변수가 노출되어 있기때문에,  모든 프로그램이 a.a를 참조하고 있기 때문에 a를 b로 바꿔도 할 수가 없다.
-> 메서드를 통해서 사용한다. )

a.setA(10);
System.out.print(a.getA()); //값을 가져온다.
(변수가 노출되지 않아서 好, 값을 다시하고 싶을 때는  위에 것만 바꾸면 되니까, 전체적인 프로그램은 고쳐질 필요가 없다. 안에 있는 프로그램은 사용자가 볼 필요가 없고, get함수만 불러오면 됨.)

** get, set 만들 규칙
:  변수명이 有時, set,get이라는 접두사를 붙이고, 변수명의 첫 글자는 대문자를  집어넣는다.
  ex) String name 時 setName , getName


---------------------
<HTML><HEAD><TITLE>Date 객체</TITLE></HEAD>
<BODY bgcolor="Goldenrod"><H3> Date 객체 예제 </H3>
<SCRIPT LANGUAGE="JavaScript">
<!--
  today = new Date();
  today.setYear(1000);
  today.setMonth(0);
  today.setDate(1);
  today.setHours(1);
  today.setMinutes(3);
  today.setSeconds(25);
  document.write("변경 날짜 : " + (today.getYear() + 1900) + " 년" +
        (today.getMonth() + 1) + " 월" + today.getDate() +"<P>");
  document.write("변경 시간 : " + today.getHours() + " 시" +
        today.getMinutes() + " 분" + today.getSeconds() + "<P>");
//자바스크립트 끝-->
</SCRIPT></BODY></HTML>
-------------------------------


p270 String 객체

변수 = “문자열"; String a = “홍";
“문자열".속성[메소드()]; “홍". [사용가능한 메소드 나옴]

String 객체의 속성과 메소드();
- split(“구분문자") : 구분문자로 문자열 분리
ex) a,b,c, 이라면  -> split(“,”) : “,” 단위로 값을 끊어서 받아온다.
 
-------------------------------------
<HTML><HEAD><TITLE>String 객체 연습</TITLE></HEAD>
<BODY><h3> 다양한 글자 모양</h3>
<SCRIPT LANGUAGE="JavaScript">
<!--
  document.write(" BIG ".big() + "<BR>")
  document.write(" SMALL ".small() + "<BR>")
  document.write(" BOLD ".bold() + "<BR>")
  document.write(" FIX ".fixed() + "<BR>")
  document.write(" ITALICS ".italics() + "<BR>")
  document.write(" STRIKE ".strike() + "<BR>")
  document.write(" SUB ".sub() + "<BR>")
  document.write(" SUPER ".sup() + "<BR>")
  document.write(" FONTCOLOR = yellow".fontcolor("yellow") + "<BR>")
  document.write(" FONTCOLOR = BLUE ".fontcolor("blue") + "<BR>")
  document.write(" FONTCOLOR = RED ".fontcolor("red") + "<BR>")
  document.write(" FONT SIZE 5 ".fontsize(5) + "<BR>")
  document.write(" FONT SIZE 10 ".fontsize(10) + "<BR>")
  document.write("파랗고 크게".big().fontcolor("blue")+"<BR>")    //여러개의 메뉴를 사용하기 (. 연산자를 이용)
  document.write("이탤릭체와 강조를 빨간색으로".italics().strike().fontcolor("red")+"<BR>")
  document.write("크기는 5이면서 볼드체로".fontsize(5).bold()+"<BR>")
// 자바스크립트 끝 -->
</SCRIPT></BODY></HTML>
-----------------------------------------
728x90
반응형

'# PRIVATE' 카테고리의 다른 글

11월 27일 수요일  (0) 2010.11.28
WEB 11월 24일 보강  (0) 2010.11.24
WEB 11월 11일  (0) 2010.11.11
template<typename TYPE>  (0) 2010.11.01
WEB  (0) 2010.10.29