<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Object 객체</title>
</head>
<body>
<script>
/*
function student(name, kor, eng, mat) {
this.name = name;
this.kor = kor;
this.eng = eng;
this.mat = mat;
this.getsum = function() {
return this.kor + this.eng + this.mat;
}
//오버라이딩
this.tostring = function() {
return this.name + this.getsum();
}
}
var ar = [];
ar.push(new student("상준", 60, 40, 30));
ar.push(new student("태연", 30, 140, 230));
ar.push(new student("유리", 20, 20, 10));
ar.push(new student("효연", 30, 40, 30));
ar.push(new student("윤하", 120, 40, 1230));
ar.push(new student("티파니", 10, 4, 3));
ar.sort(function (left,right){
return left.kor -right.kor;
});
alert(ar);
var ar = [30,20,50,10,40];
var temp;
for(var i=0;i<ar.length-1;i++){
for(var j=i+1;j<ar.length;j++){
if(ar[i]>ar[j]){
temp = ar[i];
ar[i] = ar[j];
ar[j] = temp;
}
}
}
alert(ar);
*/
var obj ={name:"이순신",address:"서울 충남"};
//자바 스크립트 객체를 문자열로 변환
var str = JSON.stringify(obj);
alert(str);
//JSON 문자열을 자바스클비트 객체로 변환
var o = JSON.parse(str);
alert(o.name);
</script>
</body>
</html>
'Web개발 > JSP, Web' 카테고리의 다른 글
[javascript] 캔버스 그리기 (0) | 2014.11.18 |
---|---|
[Ajax] Ajax xml 파싱 (0) | 2014.11.18 |
[JSP] javaseript 사용하기3 (0) | 2014.11.18 |
[JSP] javaseript 사용하기2 (0) | 2014.11.18 |
[JSP] javaseript 사용하기1 (0) | 2014.11.18 |