함수형 프로그래밍 생각해보야 할 몇 가지.


 1. 함수를 되도록 작게 만들기.

 2. 다형성 높은 함수 만들기.

 3. 상태를 변경하지 않거나 정확히 다루어 부수 효과를 최소화하기.

 4. 동일한 인자를 받으면 동일한 결과를 리턴하는 순수함수 만들기.

 5. 복잡한 객체 하나를 인자로 사용하기보다 되도록 일반적인 값 여러개를 인자로 사용하기.

 6. 큰 로직을 고차 함수로 만들고 세부 로직을 보조 함수로 완성하기.

 7. 어느 곳에서든 바로 혹은 미뤄서 실행할 수 있도록 일반 함수이자 순수 함수로 선언하기.

 8. 모델이나 컬렉션 등의 커스컴 객체보다는 기본 객체를 이용하기.

 9. 로직의 흐름을 최대한 단방향으로 흐르게 하기.

10. 작은 함수를 조합하여 큰 함수 만들기.





-- 출처 : https://www.inflearn.com/course/함수형-프로그래밍/



블로그 이미지

fallacy.kr SG's Life

댓글을 달아 주세요



function roundXL(n, digits) {
  if (digits >= 0) return parseFloat(n.toFixed(digits)); // 소수부 반올림

  digits = Math.pow(10, digits); // 정수부 반올림
  var t = Math.round(n * digits) / digits;

  return parseFloat(t.toFixed(0));
}


자바스크립트 소수점 자리수 계산

사용법 : roundXL(대상,자리수);

출처 : http://blog.naver.com/caesar0342?Redirect=Log&logNo=20120341657

블로그 이미지

fallacy.kr SG's Life

댓글을 달아 주세요

출처: http://www.webmini.net/43964



Hex Code Entity Code Number Code Character Description
  " " " Quotation Mark
  & & & Ampersand
  ⁄ / / Slash
  &lt; &#60; < Less Than Sign
  &gt; &#62; > Greater Than Sign
  &sbquo; &#130; Single Low-9 Quote
  &bdquo; &#132; Double Low-9 Quote
&#x2020; &dagger; &#134; Dagger
  &Dagger; &#135; Double Dagger
  &permil; &#137; Per Mill Sign
  &lsaquo; &#139; Single Left Angle Quote
  &lsquo; &#145; Left Single Quote
  &rsquo; &#146; Right Single Quote
  &ldquo; &#147; Left Double Quote
  &rdquo; &#148; Right Double Quote
  &trade; &#153; Trademark Symbol
  &rsaquo; &#155; Single Right Angle Quote
&#xA0; &nbsp; &#160;   Non Breaking Space
&#xA1; &iexcl; &#161; ¡ Inverted Exclamation Point
&#xA2; &cent; &#162; ¢ Cent Sign
&#xA3; &pound; &#163; £ Pound Sterling
&#xA4; &curren; &#164; ¤ General Currency Sign
&#xA5; &yen; &#165; ¥ Yen Sign
&#xA6; &brvbar; &#166; ¦ Broken Vertical Bar
&#xA7; &sect; &#167; § Section Sign
&#xA8; &uml; &#168; ¨ Umlaut (Dieresis)
&#xA9; &copy; &#169; © Copyright Symbol
&#xAA; &ordf; &#170; ª Feminine Ordinal
&#xAB; &laquo; &#171; « Left Angle Quote, Left Guillemet
&#xAC; &not; &#172; ¬ Not Sign
&#xAD; &shy; &#173; ­
Soft Hyphen
&#xAE; &reg; &#174; ® Registered Trademark
&#xAF; &macr; &#175; ¯ Macron, Overline
&#xB0; &deg; &#176; ° Degree Sign
&#xB1; &plusmn; &#177; ± Plus or Minus
&#xB2; &sup2; &#178; ² Superscript Two
&#xB3; &sup3; &#179; ³ Superscript Three
&#xB4; &acute; &#180; ´ Acute Accent
&#xB5; &micro; &#181; µ Micro Symbol
&#xB6; &para; &#182; Paragraph Symbol
&#xB7; &middot; &#183; · Middle Dot
&#xB8; &cedil; &#184; ¸ Cedilla
&#xB9; &sup1; &#185; ¹ Superscript One
&#xBA; &ordm; &#186; º Masculine Ordinal
&#xBB; &raquo; &#187; » Right Angle Quote, Right Guillemet
&#xBC; &frac14; &#188; ¼ One Fourth Fraction
&#xBD; &frac12; &#189; ½ One Half Fraction
&#xBE; &frac34; &#190; ¾ Three Forths Fraction
&#xBF; &iquest; &#191; ¿ Inverted Question Mark
&#xC0; &Agrave; &#192; À Capital A with Grave Accent
&#xC1; &Aacute; &#193; Á Capital A with Acute Accent
&#xC2; &Acirc; &#194; Â Capital A with Circumflex Accent
&#xC3; &Atilde; &#195; Ã Capital A with Tilde
&#xC4; &Auml; &#196; Ä Capital A with Dieresis/Umlaut
&#xC5; &Aring; &#197; Å Capital A with Ring
&#xC6; &AElig; &#198; Æ Capital AE Dipthong
&#xC7; &Ccedil; &#199; Ç Capital C with Cedilla
&#xC8; &Egrave; &#200; È Capital E with Grave Accent
&#xC9; &Eacute; &#201; É Capital E with Acute Accent
&#xCA; &Ecirc; &#202; Ê Capital E with Circumflex Accent
&#xCB; &Euml; &#203; Ë Capital E with Dieresis/Umlaut
&#xCC; &Igrave; &#204; Ì Capital I with Grave Accent
&#xCD; &Iacute; &#205; Í Capital I with Acute Accent
&#xCE; &Icirc; &#206; Î Capital I with Circumflex Accent
&#xCF; &Iuml; &#207; Ï Capital I with Dieresis/Umlaut
&#xD0; &ETH; &#208; Ð Capital Eth
&#xD1; &Ntilde; &#209; Ñ Capital N with Tilde
&#xD2; &Ograve; &#210; Ò Capital O with Grave Accent
&#xD3; &Oacute; &#211; Ó Capital O with Acute Accent
&#xD4; &Ocirc; &#212; Ô Capital O with Circumflex Accent
&#xD5; &Otilde; &#213; Õ Capital O with Tilde
&#xD6; &Ouml; &#214; Ö Capital O with Dieresis/Umlaut
&#xD7; &times; &#215; × Multiplication Sign
&#xD8; &Oslash; &#216; Ø Capital O with a Slash
&#xD9; &Ugrave; &#217; Ù Capital U with Grave Accent
&#xDA; &Uacute; &#218; Ú Capital U with Acute Accent
&#xDB; &Ucirc; &#219; Û Capital U with Circumflex Accent
&#xDC; &Uuml; &#220; Ü Capital U with Dieresis/Umlaut
&#xDD; &Yacute; &#221; Ý Capital Ywith Acute Accent
&#xDE; &THORN; &#222; Þ Capital Thorn
&#xDF; &szlig; &#223; ß Small Sharp s
&#xE0; &agrave; &#224; à Small a with Grave Accent
&#xE1; &aacute; &#225; á Small a with Acute Accent
&#xE2; &acirc; &#226; â Small a with Circumflex Accent
&#xE3; &atilde; &#227; ã Small a with Tilde
&#xE4; &auml; &#228; ä Small a with Dieresis/Umlaut
&#xE5; &aring; &#229; å Small a with Ring
&#xE6; &aelig; &#230; æ Small ae Dipthong
&#xE7; &ccedil; &#231; ç Small c with Cedilla
&#xE8; &egrave; &#232; è Small e with Grave Accent
&#xE9; &eacute; &#233; é Small e with Acute Accent
&#xEA; &ecirc; &#234; ê Small e with Circumflex Accent
&#xEB; &euml; &#235; ë Small e with Dieresis/Umlaut
&#xEC; &igrave; &#236; ì Small i with Grave Accent
&#xED; &iacute; &#237; í Small i with Acute Accent
&#xEE; &icirc; &#238; î Small i with Circumflex Accent
&#xEF; &iuml; &#239; ï Small i with Dieresis/Umlaut
&#xF0; &eth; &#240; ð Small eth
&#xF1; &ntilde; &#241; ñ Small n with Tilde
&#xF2; &ograve; &#242; ò Small o with Grave Accent
&#xF3; &oacute; &#243; ó Small o with Acute Accent
&#xF4; &ocirc; &#244; ô Small o with Circumflex Accent
&#xF5; &otilde; &#245; õ Small o with Tilde
&#xF6; &ouml; &#246; ö Small o with Dieresis/Umlaut
&#xF7; &divide; &#247; ÷ Division Sign
&#xF8; &oslash; &#248; ø Small o with a Slash
&#xF9; &ugrave; &#249; ù Small u with Grave Accent
&#xFA; &uacute; &#250; ú Small u with Acute Accent
&#xFB; &ucirc; &#251; û Small u with Circumflex Accent
&#xFC; &uuml; &#252; ü Small u with Dieresis/Umlaut
&#xFD; &yacute; &#253; ý Small y with Acute Accent
&#xFE; &thorn; &#254; þ Small Thorn
&#xFF; &yuml; &#255; ÿ Small y with Dieresis/Umlaut
&#x0192; &fnof; &#402; ƒ Small f with hook
&#x0391; &Alpha; &#913; Α Greek Capital Letter Alpha
&#x0392; &Beta; &#914; Β Greek Capital Letter Beta
&#x0393; &Gamma; &#915; Γ Greek Capital Letter Gamma
&#x0394; &Delta; &#916; Δ Greek Capiral Letter Delta
&#x0395; &Epsilon; &#917; Ε Greek Capital Letter Epsilon
&#x0396; &Zeta; &#918; Ζ Greek Capital Letter Zeta
&#x0397; &Eta; &#919; Η Greek Capital Letter Eta
&#x0398; &Theta; &#920; Θ Greek Capital Letter Theta
&#x0399; &Iota; &#921; Ι Greek Capital Letter Iota
&#x039A; &Kappa; &#922; Κ Greek Capital Letter Kappa
&#x039B; &Lambda; &#923; Λ Greek Capital Letter Lambda
&#x039C; &Mu; &#924; Μ Greek Capital Letter Mu
&#x039D; &Nu; &#925; Ν Greek Capital Letter Nu
&#x039E; &Xi; &#926; Ξ Greek Capital Letter Xi
&#x039F; &Omicron; &#927; Ο Greek Capital Letter Omicron
&#x03A0; &Pi; &#928; Π Greek Capital Letter Pi
&#x03A1; &Rho; &#929; Ρ Greek Capital Letter Rho
&#x03A3; &Sigma; &#931; Σ Greek Capiral Letter Sigma
&#x03A3; &Tau; &#932; Τ Greek Capital Letter Tau
  &Upsilon; &#933; Υ Greek Capital Letter Upsilon
  &Phi; &#934; Φ Greek Capital Letter Phi
  &Chi; &#935; Χ Greek Capital Letter Chi
  &Psi; &#936; Ψ Greek Capital Letter Psi
  &Omega; &#937; Ω Greek Capital Letter Omega
  &alpha; &#945; α Greek Small Letter Alpha
  &beta; &#946; β Greek Small Letter Beta
  &gamma; &#947; γ Greek Small Letter Gamma
  &delta; &#948; δ Greek Small Letter Delta
  &epsilon; &#949; ε Greek Small Letter Epsilon
  &zeta; &#950; ζ Greek Small Letter Zeta
  &eta; &#951; η Greek Small Letter Eta
  &theta; &#952; θ Greek Small Letter Theta
  &iota; &#953; ι Greek Small Letter Iota
  &kappa; &#954; κ Greek Small Letter Kappa
  &lambda; &#955; λ Greek Small Letter Lambda
  &mu; &#956; μ Greek Small Letter Mu
  &nu; &#957; ν Greek Small Letter Nu
  &xi; &#958; ξ Greek Small Letter Xi
  &omicron; &#959; ο Greek Small Letter Omicron
  &pi; &#960; π Greek Small Letter Pi
  &rho; &#961; ρ Greek Small Letter Rho
  &sigmaf; &#962; ς Greek Small Letter Final Sigma
  &sigma; &#963; σ Greek Small Letter Sigma
  &tau; &#964; τ Greek Small Letter Tau
  &upsilon; &#965; υ Greek Small Letter Upsilon
  &phi; &#966; φ Greek Small Letter Phi
  &chi; &#967; χ Greek Small Letter Chi
  &psi; &#968; ψ Greek Small Letter Psi
  &omega; &#969; ω Greek Small Letter Omega
  &thetasym; &#977; ϑ Greek Small Letter Theta Symbol
  &upsih; &#978; ϒ Greek Upsilon with Hook Symbol
  &piv; &#982; ϖ Greek pi Symbol
  &bull; &#8226; Bullet / Black Small Circle
  &hellip; &#8230; Horizontal Ellipsis
  &prime; &#8242; Prime / Minutes / Feet
  &Prime; &#8243; Double Prime / Seconds / Inches
  &oline; &#8254; Overline
  &image; &#8465; Blackletter Capital I / Imaginary Part
  &weierp; &#8472; Script Capital P / Power Set
  &real; &#8476; Blackletter Capital R / Real Part Symbol
  &alefsym; &#8501; Alef Symbol / First Transfinite Cardinal
  &larr; &#8592; Left Arrow
  &uarr; &#8593; Up Arrow
  &rarr; &#8594; Right Arrow
  &darr; &#8595; Down Arrow
  &harr; &#8596; Left-Right Arrow
  &crarr; &#8629; Carrige Return / Downward Left Arrow
  &lArr; &#8656; Double Left Arrow
  &uArr; &#8657; Double Up Arrow
  &rArr; &#8658; Double Right Arrow
  &dArr; &#8659; Double Down Arrow
  &hArr; &#8660; Double Left-Right Arrow
  &forall; &#8704; For All
  &part; &#8706; Partial Differential
  &exist; &#8707; There Exists
  &empty; &#8709; Empty Set
  &nabla; &#8711; Nabla / Backwards Difference
  &isin; &#8712; Element Of
  &notin; &#8713; Not An Element of
  &ni; &#8715; Contains As Member
  &prod; &#8719; Product Sign
  &sum; &#8721; Sumation
  &minus; &#8722; Minus Sign
  &lowast; &#8727; Asterisk Operator
  &radic; &#8730; Square Root / Radical Sign
  &prop; &#8733; Proportional To
  &infin; &#8734; Infinity
  &ang; &#8736; Angle
  &and; &#8743; Logical And / Wedge
  &or; &#8744; Logical Or / Vee
  &cap; &#8745; Inersection / Cap
  &cup; &#8746; Union / Cup
  &int; &#8747; Integral
  &there4; &#8756; Therefore
  &sim; &#8764; Tilde Operator / Similar To / Varies With
  &cong; &#8773; Approximately Equal To
  &asymp; &#8776; Almost Equal To / Asymptotic To
  &ne; &#8800; Not Equal To
  &equiv; &#8801; Identical To
  &le; &#8804; Less Than or Equal To
  &ge; &#8805; Greater Than or Equal To
  &sub; &#8834; Subset Of
  &sup; &#8835; Superset Of
  &nsub; &#8836; Not A Subset Of
  &sube; &#8838; Subset Of Or Equal To
  &supe; &#8839; Superset Of Or Equal To
  &oplus; &#8853; Circled Plus / Direct Sum
  &otimes; &#8855; Circled Times / Vector Product
  &perp; &#8869; Up Tack / Orthogonal To / Perpendicular
  &sdot; &#8901; Dot Operator
  &lceil; &#8968; Left Ceiling / Apl Upstile
  &rceil; &#8969; Right Ceiling
  &lfloor; &#8970; Left Floor / Apl Downstile
  &rfloor; &#8971; Right Floor
  &lang; &#9001; Left-Pointing Angle Bracket / Bra
  &rang; &#9002; Right-Pointing Angle Bracket / Ket
  &loz; &#9674; Lozenge
  &spades; &#9824; Black Spade Suit
  &clubs; &#9827; Black Club Suit
  &hearts; &#9829; Black Heart Suit
  &diams; &#9830; Black Diamond Suit
블로그 이미지

fallacy.kr SG's Life

댓글을 달아 주세요

<script language="JavaScript">
//모바일 페이지로 이동.
//http://en.wikipedia.org/wiki/List_of_user_agents_for_mobile_phones
var uAgent = navigator.userAgent.toLowerCase();
var mobilePhones = new Array('iphone','ipod','android','blackberry','windows ce',
        'nokia','webos','opera mini','sonyericsson','opera mobi','iemobile');
for(var i=0;i<mobilePhones.length;i++)
    if(uAgent.indexOf(mobilePhones[i]) != -1)
        document.location = "http://"+ location.host +"/m" + location.pathname;
</script>

블로그 이미지

fallacy.kr SG's Life

댓글을 달아 주세요

httpRequest.js

HTML/JS/CSS 2011.05.24 11:21
//XMLHttpRequest객체를 생성해 주는 getXMLHttpRequest()함수

function getXMLHttpRequest() {
 if (window.ActiveXObject) {
  try {
   return new ActiveXObject("Msxml2.XMLHTTP");
  } catch(e) {
   try {
    return new ActiveXObject("Microsoft.XMLHTTP");
   } catch(e1) { return null; }
  }
 } else if (window.XMLHttpRequest) {
  return new XMLHttpRequest();
 } else {
  return null;
 }
}


//생성된 XMLHttpRequest객체를 저장할 전역변수
var httpRequest = null;

//XMLHttpRequest객체를 사용해서 지정한방식,지정한 URL, 첨부할 파라미터 값을 사용하여 웹 서버에 요청을 전송

function sendRequest(url, params, callback, method) {
 httpRequest = getXMLHttpRequest();
 var httpMethod = method ? method : 'GET';
 if (httpMethod != 'GET' && httpMethod != 'POST') {
  httpMethod = 'GET';
 }
 var httpParams = (params == null || params == '') ? null : params;
 var httpUrl = url;
 if (httpMethod == 'GET' && httpParams != null) {
  httpUrl = httpUrl + "?" + httpParams;
 }
 httpRequest.open(httpMethod, httpUrl, true);
 httpRequest.setRequestHeader( //컨텐트 타입 지정
  'Content-Type', 'application/x-www-form-urlencoded');
 httpRequest.onreadystatechange = callback; //readyState값이 바뀔 때 호출 될 콜백 함수 지정
 httpRequest.send(httpMethod == 'POST' ? httpParams : null); //Http요청 방식이 'POST'이면 send()함수를 통해 파라미터 파라미터 전송
}
블로그 이미지

fallacy.kr SG's Life

댓글을 달아 주세요

출처 : http://naver.catchstyle.net/90091110491


   <script language = 'javascript' >
    opener.location.reload();
    if(navigator.appVersion.indexOf("MSIE 7.0") >= 0 ){  //익스플로러 체크
     window.open("RNCheckRequest.jsp","_self").close();
    }else if(navigator.appVersion.indexOf("MSIE 8.0") >= 0){    //보안 alert! 방지
     window.open("RNCheckRequest.jsp","_self").close();
    }else{
     self.close();
    }
   </script>

self.close() 시 사용했던 소스. 자기 자신의 파일명을 써줬던 것 같다.



출처 : http://naver.catchstyle.net/90091110491
블로그 이미지

fallacy.kr SG's Life

댓글을 달아 주세요

출처 : http://webstandards.or.kr/html5


블로그 이미지

fallacy.kr SG's Life

Tag html5

댓글을 달아 주세요

Ajax XMLHttpRequest

HTML/JS/CSS 2010.09.17 05:35

http://skyunoe.blog.me/20108801554


Ajax를 구현하는 핵심 JavaScript 객체는 XMLHttpRequest이다.

Ajax가 추구하는 새롭고 놀라운 기능을 실제로 구현하기 위해서는 이 객체에 대해 완전히 익숙해 져야 한다.

 

아래는 XMLHttpRequest객체가 지원하는 Method 및 Properties들을 정리한 것이다.

 

Method

  • open(): 새로운 요청을 서버에 설정함.
  • send(): 요청을 서버에 전송함.
  • abort(): 현 요청에서 벗어남.
  • readyState: 현 HTML 준비상태를 제공함.
  • responseText: 요청에 응답하기 위해 서버에서 재전송하는 텍스트.

Properties

  • onreadystatechange : XMLHttpRequest객체의 상태가 변할 때 실행할 핸들러를 지정 한다.
  • readyState : XMLHttpRequest객체의 생태가 변할 때 각 상태값을 반환한다.
    • 0: (open()을 호출하기 전에는) 요청이 초기화 되지 않는다.
    • 1: (send()를 호출하기 전에는) 요청은 설정은 되지만 보내지지 않는다.
    • 2: 요청이 보내지고 처리 중에 있다. (이 시점에서 응답에서 콘텐트 헤더를 얻을 수 있다.)
    • 3: 요청이 처리 중에 있다. 부분적인 데이터를 응답에서 사용할 수 있지만 서버는 이 응답으로는 종료되지 않는다.
    • 4: 응답이 완료된다. 서버의 응답을 받고 이를 사용한다.
  • responseText : HTTP 요청결과를 문자열 형태로 반환한다.
  • responseXML: HTTP 요청결과를 XMLDocument 오브젝트로 반환한다.
  • responseBody
  • status: HTTP 응답코드를 반환한다. 성공일 경우 200
  • statusText: HTTP 응답문자열을 반환한다. 성공인 경우 OK

 

사용법

 

1. 요청생성

 

  function getXMLHttpRequest() {


       var xmlreq = false;
       if (window.XMLHttpRequest) {
           // Create XMLHttpRequest object in non-Microsoft browsers
          xmlreq = new XMLHttpRequest();


       } else if (window.ActiveXObject) {
         
 // Create XMLHttpRequest via MS ActiveX
           try {
             
 // Try to create XMLHttpRequest in later versions
               // of Internet Explorer

               xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
           } catch (e1) {
               // Failed to create required ActiveXObject
               try {
                 
 // Try version supported by older versions
                   // of Internet Explorer

                   xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
               } catch (e2) {
                  
// Unable to create an XMLHttpRequest with ActiveX
               }
           }
       }


       return xmlreq;
   }

 

 

2. 요청

 

    function ajaxRequest() {


                // req 객체반환
                req = getXMLHttpRequest();
 
                // 응답이 완료되면 자동으로 실행되도록 JavaScript 콜백 함수를 정의
                var handlerFunction = "";
                req.onreadystatechange = handlerFunction;
 
                // 요청처리
                req.open("POST", "test.php", true);
 
                // 헤더 설정
                req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 
                // POST일 경우 send에 아래와 같이 변수를 입력하고 GET일 경우 null입력
                req.send("변수=값");

    }

 

 

3. CallBack (요청에 대한 응답 처리)

 

    function ajaxResponse() {

            // only if req shows "loaded"
            if (req.readyState == 4) {
                 // only if "OK"
                 if (req.status == 200) {
                    // do something...
                 } else {
                    alert("There was a problem retrieving the XML data:\n" + req.statusText);
                 }
            }

    }

 

[출처] [Ajax] XMLHttpRequest객체|작성자 깡통

블로그 이미지

fallacy.kr SG's Life

댓글을 달아 주세요