javascript의 prototype이란?

Javascript 2007. 12. 10. 12:25
javascript 프레임웍인 prototype을 말하는게 아님! (ㅋㅋ)
 
prototype이란?
prototype 속성은 개체에 새로운 속성이나 메소드를 추가할 때 사용한다.
다음 예제를 보면 쉽게 이해 할 수 있음.
 
String.prototype.ltrim = function() {
    return this.replace(/(^s*)/, "");
}
위의 구문은 javascript String개체에 ltrim이라는 함수는 추가한것이다.
 
사용법은
var str = "abcdaass       ";
var conStr = str.ltrim();
 
위와 같이 사용한다.

설정

트랙백

댓글