라벨이 JS인 게시물 표시

[JS] 웹 브라우저가 자바 스크립트의 선언적 함수와 익명 함수 읽는 순서

출처 - 모던 웹을 위한 JavaScript + jQuery 입문 (저자 - 윤인성) 함수(); var 함수 = function () { alert("함수 A"); }; var 함수 = function () { alert("함수 B"); }; 위와 같은 코드는 변수를 선언하기 이전에 변수를 사용했기 때문에 오류가 발생해 실행되지 않습니다. 하지만, 함수(); function 함수() { alert("함수 A"); }; function 함수() { alert("함수 B"); }; 위와 같은 코드는 웹 브라우저가 script 태그 내부의 내용을 읽기 전에 선언적 함수부터 읽기 때문에 정상적으로 코드가 실행됩니다. 따라서, var 함수 = function () { alert("함수 A"); }; function 함수() { alert("함수 B"); }; 함수(); 위와 같은 코드가 있으면 선언적 함수가 먼저 분석되기 때문에 상대적으로 더 나중에 분석되는 익명 함수가 호출 됩니다.

[JS] 브라우저가 지원하는 기능 체크 & 하드웨어 정보

브라우저가 지원하는 기능 체크 modernizr https://modernizr.com/ 하드웨어 정보 detectizr https://github.com/barisaydinoglu/Detectizr 공식 홈페이지는 없는 듯 Github를 통해 라이브러리 파일(.js)을 제공하고 있음.

[JS] OS 종류 구하는 함수

// This script sets OSName variable as follows: // "Windows" for all versions of Windows // "MacOS" for all versions of Macintosh OS // "Linux" for all versions of Linux // "UNIX" for all other UNIX flavors // "Unknown OS" indicates failure to detect the OS new function () { var OsNo = navigator.userAgent.toLowerCase(); jQuery.os = { Linux: /linux/.test(OsNo), Unix: /x11/.test(OsNo), Mac: /mac/.test(OsNo), Windows: /win/.test(OsNo) } } function GetOperatingSystem() { var tempUserAgent = navigator.userAgent.replace(/ /g, ''); var operatingSystem = ""; if ($.os.Windows) { if (tempUserAgent.indexOf("WindowsCE") != -1) { operatingSystem = "Windows CE"; } else if (tempUserAgent.indexOf("Windows95") != -1) { operatingSystem = "Windows 95"; } else if (tempUserAgent.indexOf("Windows98") != -1) { if (tempUserAgent.indexOf("Win9x4.90"...

[JS] OS 아키텍처 구하는 함수

function GetOperatingSystemArch() { var tempUserAgent = navigator.userAgent.replace(/ /g, ''); var operatingSystemArch = ""; if ($.os.Windows) { if (tempUserAgent.indexOf("WOW64") != -1) { operatingSystemArch = "WOW64"; } else if (tempUserAgent.indexOf("Win64;x64") != -1) { operatingSystemArch = "Win64 on x64"; } else if (tempUserAgent.indexOf("Win16") != -1) { operatingSystemArch = "16-bit"; } else { operatingSystemArch = "x86"; } } else if ($.os.Linux) { if (tempUserAgent.indexOf("x86_64") != -1) { operatingSystemArch = "x86_64"; } else if (tempUserAgent.indexOf("i686") != -1) { operatingSystemArch = "i686"; } else if (tempUserAgent.indexOf("i686 on x86_64") != -1) { operatingSystemArch = "i686 running on x86_64"; } else if (tempUserAgent.indexOf("armv7l") != -1) { opera...

[JS] 안드로이드 디바이스 이름 구하는 함수

// Android의 단말 이름을 반환 function GetAndroidDevName() { var uaAdata = navigator.userAgent; var regex = /Android (.*);.*;\s*(.*)\sBuild/; var match = regex.exec(uaAdata); if (match) { var ver = match[1]; var dev_name = match[2]; return "Android " + ver + " " + dev_name; } return "Android OS"; }

[JS] 브라우저 알아내는 함수

// browser detect var Browser = (function() { var s = navigator.userAgent.toLowerCase(); var match = /(webkit)[ \/](\w.]+)/.exec(s) || /(opera)(?:.*version)?[ \/](\w.]+)/.exec(s) || /(msie) ([\w.]+)/.exec(s) || !/compatible/.test(s) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec(s) || []; return { name: match[1] || "", version: match[2] || "0" }; }()); 사용 예) alert(Browser.name);