posted by 뚱2

링크: http://ejohn.org/blog/javascript-method-overloading/


Overriding 기능찾다가 찾게 되었다. 나중에 써먹어야겠다.

참고로 존레식은 jQuery 만든 사람이다.


// addMethod - By John Resig (MIT Licensed)

function addMethod(object, name, fn){

    var old = object[ name ];

    object[ name ] = function(){

        if ( fn.length == arguments.length )

            return fn.apply( this, arguments );

        else if ( typeof old == 'function' )

            return old.apply( this, arguments );

    };

}



posted by 뚱2

[ScalaJs] Scala.js

JavaScript/JavaScript 2014.06.22 11:49

참 재미있는 개발이다.

서버사이드 언어를 자바스크립트로 만들다니.

링크: http://www.scala-js.org/

posted by 뚱2

링크: http://www.howtocreate.co.uk/tutorials/javascript/browserwindow


function getSize() {

  var myWidth = 0, myHeight = 0;

  if( typeof( window.innerWidth ) == 'number' ) {

    //Non-IE

    myWidth = window.innerWidth;

    myHeight = window.innerHeight;

  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {

    //IE 6+ in 'standards compliant mode'

    myWidth = document.documentElement.clientWidth;

    myHeight = document.documentElement.clientHeight;

  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {

    //IE 4 compatible

    myWidth = document.body.clientWidth;

    myHeight = document.body.clientHeight;

  }

  return [myWidth, myHeight];

}



function getScrollXY() {

  var scrOfX = 0, scrOfY = 0;

  if( typeof( window.pageYOffset ) == 'number' ) {

    //Netscape compliant

    scrOfY = window.pageYOffset;

    scrOfX = window.pageXOffset;

  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {

    //DOM compliant

    scrOfY = document.body.scrollTop;

    scrOfX = document.body.scrollLeft;

  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {

    //IE6 standards compliant mode

    scrOfY = document.documentElement.scrollTop;

    scrOfX = document.documentElement.scrollLeft;

  }

  return [ scrOfX, scrOfY ];

}


posted by 뚱2

[JavaScript] RegExr

JavaScript/JavaScript 2014.06.14 00:15

자바스크립트 정규표현식 테스트 하기 좋은 곳

링크: http://www.regexr.com/


posted by 뚱2

링크: http://www.w3schools.com/jsref/jsref_shift.asp

링크: http://www.w3schools.com/jsref/jsref_pop.asp


shift: 배열의 앞쪽을 리턴하고 배열에서 삭제한다.

pop: 배열의 뒷쪽을 리턴하고 배열에서 삭제한다.

posted by 뚱2

링크: http://jsfiddle.net/

자바스크립트를 테스트 할수 있는 환경

posted by 뚱2

/*

* strTemp  : [필수] 크로스사이트 스크립팅을 검사할 문자열

* level    : [옵션] 검사레벨

*            0 (기본) -> XSS취약한 문자 제거

*            1 (선택) -> 단순한 <, > 치환

*/

function XSS_Check(strTemp, level) {     

if ( level == undefined || level == 0 ) {

strTemp = strTemp.replace(/\<|\>|\"|\'|\%|\;|\(|\)|\&|\+|\-/g,"");

}

else if (level != undefined && level == 1 ) {

strTemp = strTemp.replace(/\</g, "&lt;");

strTemp = strTemp.replace(/\>/g, "&gt;");

}

return strTemp;

}


posted by 뚱2

var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;

var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;

var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;


posted by 뚱2

링크 : http://www.w3schools.com/jsref/jsref_regexp_source.asp 

Definition and Usage

The source property returns the text of the RegExp pattern.

Syntax

RegExpObject.source


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The source property is supported in all major browsers.


Example

Example

Return the text of the RegExp pattern:

<script>

var str="Visit W3Schools";
var patt1=/W3S/g;
document.write("The text of the RegExp is: " + patt1.source);

</script>

Try it yourself »

posted by 뚱2

//==================================================================

// 스크립트 오류 메세지

//==================================================================

function myDebug(errmsg, url, linenum)

{

    errWin=window.open('','','width=350,height=220,scrollbars=no');

    errWin.document.open();

    errWin.document.write('<CENTER><H1>스크립트오류 정보</H2></CENTER>');

    errWin.document.write('에러메시지: <FONT COLOR=RED>'+errmsg+'</FONT><BR>');

    errWin.document.write('에러가 난 문서: <FONT COLOR=RED>'+url+'</FONT><BR>');

    errWin.document.write('에러가 난 라인: <FONT COLOR=RED>'+linenum+'</FONT>');

    errWin.document.close();


    return true;

}

window.onerror=myDebug;


posted by 뚱2