검색결과 리스트
글
[Windows Script Host] Windows Script Host를 이용해서 자바스크립트를 테스트 해보자
설정
;(function(exports, $) {
/**
* 전달받은 인자를 부모로 하는 새로운 객체를 생성한다.
*/
if ( typeof Object.create !== 'function' ) {
Object.create = function(o) {
var F = function() {};
if ( !arguments.length ) {
F.prototype = o;
}
return new F();
};
}
/**
* 객체에 메소드를 추가하는 메소드
* @param name
* @param code
*/
Function.prototype.method = function(name, code) {
if ( !this.prototype[name] ) {
this.prototype[name] = code;
}
};
/**
* 함수설명 : " abcde " -> "abcde" 공백제거
* 예제 : str.trim();
*/
String.method("trim", function(){
return this.replace(/(^\s*)|(\s*$)/g, "");
});
/**
* 함수설명 : " ab c de " -> "abcde" 모든 공백제거
* 예제 : str.allTrim()
*/
String.method("allTrim", function(){
return this.replace(/\s*/g, "");
});
/**
* 함수설명 : " abcd" -> "abcd"
* 왼쪽 공백 제거
*/
String.method("leftTrim", function() {
return this.replace(/(^\s*)/g, "");
});
/**
* 함수설명 : "abcd " -> "abcd"
* 오른쪽 공백 제거
*/
String.method("rightTrim", function() {
return this.replace(/(\s*$)/g, "");
});
/**
*함수설명 : cut 메소드를 추가
* start : 잘라낼 시작 위치 (int)
* length : 잘라낼 문자열 길이 (int)
* 예제 : str.cut(2, 2);
*/
String.method("cut", function(start, length){
return this.substring(0, start) + this.substr(start + length);
});
/**
* 왼쪽으로 문자열을 잘라낸다. (substring과 같은 기능이다.)
*/
String.method("left", function(len) {
return this.substring(0, len);
});
/**
* 오른쪽에서 문자열을 잘라낸다.
*/
String.method("right", function(len) {
return this.substring(this.length-len);
});
/**
* 가운데에서 문자열을 잘라낸다.
*/
String.method("mid", function(start, len) {
if ( start > 0 ) {
start = start - 1;
}
else {
throw "시작위치는 1부터 입니다.";
}
if ( len == undefined ) {
return this.substring(start);
}
return this.substring(start, start+len);
});
/**
* 문자열을 숫자로 바꿔준다.
* 숫자로 변환할수 없는 문자는 0을 리턴한다.
*/
String.method("toNumber", function() {
var num = Number(this.replace(/[,\s]/g, ""));
return (isNaN(num) ? 0 : num);
});
/**
* 숫자 부분에서 정수만 추출 하는 메소드
*/
Number.method("integer", function() {
return Math[this < 0 ? "ceiling" : "floor"](this);
});
exports.alert = function(msg) {
$.Echo(msg);
};
exports.$ = $;
})(this, WScript);
// 메인
;(function() {
alert("메인입니다.");
})();
'JavaScript > Windows Script Host' 카테고리의 다른 글
[Windows Script Host] javascript를 간단하게 테스트 해보자 (0) | 2012.08.29 |
---|---|
[Windows Script Host] 즐겨찾기 (0) | 2012.02.09 |
RECENT COMMENT