;(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("메인입니다.");

})();


posted by 뚱2

윈도우에서 javascript를 사용할수 있는 방법
CreateObject로 COM을 사용할수 있기때문에 조금만 머리 굴리면 웬만한건 다 될듯 하다.

 


Object Model : http://msdn.microsoft.com/ko-kr/library/a74hyyw0.aspx
링크         : http://msdn.microsoft.com/ko-kr/library/9bbdkx3k.aspx
Reference : http://msdn.microsoft.com/ko-kr/library/98591fh7.aspx
참고         : http://bybi.tistory.com/320

 

간단한 javascript 코드를 테스트 한다거나 유틸리티성 변환 프로그램을 만들때 쉽고 가볍게 만들수 있어


애용 하고 있습니다.


요즘 추세대로 익명함수를 바로 호출하여 지역화 시켜서 사용하면 편합니다.


Windows Host Script : http://www.taeyo.pe.kr/lecture/20_Tips/wsh_01.htm 


// 테스트 코드

(function($) {

var msg    = "기본신청기간(2011년 11월 01일 ~ 2012년 01월 05일 )";

var result = /.*?\((.*?)\).*?/gi.exec(msg);

if ( result != null )

{

$.Echo(result[1]);

}

})(WScript);


posted by 뚱2
윈도우에서 javascript를 사용할수 있는 방법
CreateObject로 COM을 사용할수 있기때문에 조금만 머리 굴리면 웬만한건 다 될듯 하다.

링크 : http://msdn.microsoft.com/ko-kr/library/9bbdkx3k.aspx
Reference : http://msdn.microsoft.com/ko-kr/library/98591fh7.aspx
참고 : http://bybi.tistory.com/320


posted by 뚱2