Latest web development tutorials

자바 스크립트 날짜 프로토 타입 속성

날짜 객체 참조 자바 스크립트 날짜 개체

새 날짜 객체 메소드를 만듭니다

Date.prototype.myMet=function()
{
if (this.getMonth()==0){this.myProp="January"};
if (this.getMonth()==1){this.myProp="February"};
if (this.getMonth()==2){this.myProp="March"};
if (this.getMonth()==3){this.myProp="April"};
if (this.getMonth()==4){this.myProp="May"};
if (this.getMonth()==5){this.myProp="June"};
if (this.getMonth()==6){this.myProp="July"};
if (this.getMonth()==7){this.myProp="August"};
if (this.getMonth()==8){this.myProp="Spetember"};
if (this.getMonth()==9){this.myProp="October"};
if (this.getMonth()==10){this.myProp="November"};
if (this.getMonth()==11){this.myProp="December"};
}

Date 객체를 생성, myMet 객체 메소드를 호출합니다

var d = new Date();
d.myMet();
var monthname = d.myProp;

MONTHNAME 출력 :

var d = new Date(); d.myMet(); document.write(d.myProp);

»시도

정의 및 사용

prototype 속성은 당신에게 객체에 속성과 메소드를 추가 할 수있는 기능을 제공합니다.

프로토 타입을 구성 할 때, 모든 날짜 개체는 기본 속성과 방법으로 추가됩니다.

참고 : 프로토 타입 속성과 메서드를 추가 할 수 있지만 다른 프로토 타입 객체를 할당 할 수 없습니다.그러나 사용자 정의 개체에 새로운 프로토 타입을 할당 할 수 있습니다.

참고 : 프로토 타입은 전역 속성,있는 거의 모든 자바 스크립트 객체의합니다.


브라우저 지원

Internet ExplorerFirefoxOperaGoogle ChromeSafari

모든 주요 브라우저는 프로토 타입 속성을 지원합니다.


문법

Date.prototype. name = value


날짜 객체 참조 자바 스크립트 날짜 개체