<script language="JSCRIPT">
function setPrice(price){
this.price = price
}
function setColor(color){
this.color = color
}
function Car(color,price){
this.color = color
this.price = price
this.alert = alert
this.setColor = setColor
this.setPrice = setPrice
}
//참조 car 로 Car 객체 생성
var car = new Car("red",500)
//Car 객체의 메써드 alert 로 초기화된 color,price 변수를 표시
car.alert("variable 'color' is " + car.color + "nvarialbe 'price' is " + car.price)
//Car 객체의 메써드 setColor,setPrice 로 변수 변경
car.setColor("blue")
car.setPrice(800)
//다시 변수 표시
car.alert("variable 'color' is " + car.color + "nvarialbe 'price' is " + car.price)
//Car 객체에 prototype 을 이용 새 메써드 추가
Car.prototype.prompt = prompt
//Car 객체에 새로운 변수 driver 추가
car.driver = car.prompt("이름을 적으세요","")
//Car 객체의 메써드 alert 를 다른 메써드로 변경
car.alert = confirm
//Car 객체의 변경된 메써드 alert 로 변수 driver 표시
car.alert(car.driver+" is driving this car")
//객체 해제
car = null
var otherCar = new Car("red",500)
//위에서 재정의된 Car 객체의 메써드 alert 가 아직도 유효한지 검사
otherCar.alert("test") //결과 - 유효하지 않음
//위에서 추가된 Car 객체의 메써드 prompt 가 아직도 유효한지 검사
otherCar.prompt("","") //결과 - 유효함
//Car 객체에 prototype 을 이용 새 메써드 추가
Car.prototype.returnAll = function()
{
str = "공용변수와 메써드 리스트" + "n"
str += "this.color = " + this.color + "n"
str += "this.price = " + this.price + "n"
str += "this.setPrice = " + this.setPrice + "n"
str += "this.setColor = " + this.setColor
return str
}
//새로 추가된 returnAll 확인
a = otherCar.returnAll()
otherCar.alert(a)
var otherCar = null
</script>
function setPrice(price){
this.price = price
}
function setColor(color){
this.color = color
}
function Car(color,price){
this.color = color
this.price = price
this.alert = alert
this.setColor = setColor
this.setPrice = setPrice
}
//참조 car 로 Car 객체 생성
var car = new Car("red",500)
//Car 객체의 메써드 alert 로 초기화된 color,price 변수를 표시
car.alert("variable 'color' is " + car.color + "nvarialbe 'price' is " + car.price)
//Car 객체의 메써드 setColor,setPrice 로 변수 변경
car.setColor("blue")
car.setPrice(800)
//다시 변수 표시
car.alert("variable 'color' is " + car.color + "nvarialbe 'price' is " + car.price)
//Car 객체에 prototype 을 이용 새 메써드 추가
Car.prototype.prompt = prompt
//Car 객체에 새로운 변수 driver 추가
car.driver = car.prompt("이름을 적으세요","")
//Car 객체의 메써드 alert 를 다른 메써드로 변경
car.alert = confirm
//Car 객체의 변경된 메써드 alert 로 변수 driver 표시
car.alert(car.driver+" is driving this car")
//객체 해제
car = null
var otherCar = new Car("red",500)
//위에서 재정의된 Car 객체의 메써드 alert 가 아직도 유효한지 검사
otherCar.alert("test") //결과 - 유효하지 않음
//위에서 추가된 Car 객체의 메써드 prompt 가 아직도 유효한지 검사
otherCar.prompt("","") //결과 - 유효함
//Car 객체에 prototype 을 이용 새 메써드 추가
Car.prototype.returnAll = function()
{
str = "공용변수와 메써드 리스트" + "n"
str += "this.color = " + this.color + "n"
str += "this.price = " + this.price + "n"
str += "this.setPrice = " + this.setPrice + "n"
str += "this.setColor = " + this.setColor
return str
}
//새로 추가된 returnAll 확인
a = otherCar.returnAll()
otherCar.alert(a)
var otherCar = null
</script>
'Web > Javascript' 카테고리의 다른 글
프린트 (0) | 2013.09.26 |
---|---|
this.blur() (0) | 2013.09.26 |
메인 다중 게시판 보이기 (0) | 2013.09.26 |
이미지 페이드 (0) | 2013.09.26 |
서브 레이어 메뉴 ( 클릭 ) 메뉴 (0) | 2013.09.26 |