이라고만 선언하는데, C언어적인 관점에서는 도무지 있을수 없는 녀석이라 혼돈을 더해주고만 있어서
검색을 해보지만 이렇다 할 레퍼런스를 찾지는 못했다.
간략하게만 정리하자면
1. var 를 붙이지 않으면 자동으로 "전역변수"로 선언되며
var 를 붙이지 않은 변수는 window 오브젝트(혹은 컨텍스트?)에 선언된다.
2. javascript 는 dynamic scope 이기 때문에 함수에서 변수를 사용시에는
함수가 어디에 선언되었냐 보다는, 어디에서 함수가 불려지냐는 "문맥(context)"가 중요해 진다고 한다.
3. 그리고 var로 선언한 변수는 delete 키워드로 메모리를 해제할수 없다.
아무튼 ECMA 표준을 보던가 해서 명확하게 좀 찾아볼 필요가 있어 보인다.
말씀하신 local에 생기는 경우는 var를 붙였을 경우 입니다.
var를 붙이지 않으면..최상위 Context인 window에 생성이 됩니다.
// states
const unsigned short UNSENT = 0;
const unsigned short OPENED = 1;
const unsigned short HEADERS_RECEIVED = 2;
const unsigned short LOADING = 3;
const unsigned short DONE = 4;
readonly attribute unsigned short readyState;
javascript 에서 window 객체가 최상위 객체라고 하길래
어떤 객체들이 있나, 어떤 함수들이 있나 for...in 을 이용해서 출력했다.
하지만 출력하다 죽는 문제가 있어 해결방법을 찾던중
try..catch 문이란게 있었고 e.message 로 메시지를 출력하면 계속 진행하는 것을 발견했다.
음.. 문법은 거의 C++에 가까운 느낌이라고 해야하나..
<html>
<script type="text/javascript">
document.write("<hr><H1>window</H1>");
for (i in window)
{
try
{
if(typeof(window[i]) == 'object')
document.write("<B>",i,"</B><br>");
else document.write(window[i], "<br>");
}
catch(e)
{
document.write(i,"-");
document.write("<font color=red>",e.message, "</font><br>");
}
}
document.write("<hr><H1>document</H1>");
for (i in document)
{
try
{
if(typeof(document[i]) == 'object')
document.write("<B>",i,"</B><br>");
else document.write(document[i], "<br>");
}
catch(e)
{
document.write(i,"-");
document.write("<font color=red>",e.message, "</font><br>");
}
}
document.write("<hr><H1>location</H1>");
for (i in location)
{
try
{
if(typeof(location[i]) == 'object')
document.write("<B>",i,"</B><br>");
else document.write(location[i], "<br>");
}
catch(e)
{
document.write(i,"-");
document.write("<font color=red>",e.message, "</font><br>");
}
}
document.write("<hr><H1>history</H1>");
for (i in history)
{
try
{
if(typeof(history[i]) == 'object')
document.write("<B>",i,"</B><br>");
else document.write(history[i], "<br>");
}
catch(e)
{
document.write(i,"-");
document.write("<font color=red>",e.message, "</font><br>");
}
}
document.write("<hr><H1>navigator</H1>");
for (i in navigator)
{
try
{
if(typeof(navigator[i]) == 'object')
document.write("<B>",i,"</B><br>");
else document.write(navigator[i], "<br>");
}
catch(e)
{
document.write(i,"-");
document.write("<font color=red>",e.message, "</font><br>");
}
}
</script>
</html>
Firefox / IE8
window
function getInterface() {
[native code]
} window document navigator netscape
function
XPCSafeJSObjectWrapper() {
[native code]
}
function XPCNativeWrapper() {
[native code]
} Components
sessionStorage-Operation is
not supported globalStorage
function
getComputedStyle() {
[native code]
}
function dispatchEvent() {
[native code]
}
function removeEventListener() {
[native code]
}
parent top
function dump() {
[native code]
}
function getSelection() {
[native code]
}
function scrollByLines() {
[native code]
} scrollbars
0
0
function scrollTo() {
[native code]
}
function scrollBy() {
[native code]
}
function scrollByPages() {
[native code]
}
function sizeToContent() {
[native code]
}
function setTimeout() {
[native code]
}
function setInterval() {
[native code]
}
function clearTimeout() {
[native code]
}
function clearInterval() {
[native code]
}
function setResizable() {
[native code]
}
function captureEvents() {
[native code]
}
function releaseEvents() {
[native code]
}
function routeEvent() {
[native code]
}
function enableExternalCapture() {
[native code]
}
function disableExternalCapture() {
[native code]
}
function open() {
[native code]
}
function openDialog() {
[native code]
} frames applicationCache self screen history content menubar toolbar locationbar personalbar statusbar directories
false crypto pkcs11 controllers opener
location
1074
762
1082
895
159
42
163
149
0
0
0
577
0
false
function
alert() {
[native code]
}
function confirm() {
[native code]
}
function prompt() {
[native code]
}
function focus() {
[native code]
}
function blur() {
[native code]
}
function back() {
[native code]
}
function forward() {
[native code]
}
function home() {
[native code]
}
function stop() {
[native code]
}
function print() {
[native code]
}
function moveTo() {
[native code]
}
function moveBy() {
[native code]
}
function resizeTo() {
[native code]
}
function resizeBy() {
[native code]
}
function scroll() {
[native code]
}
function close() {
[native code]
}
function updateCommands() {
[native code]
}
function find() {
[native code]
}
function atob() {
[native code]
}
function btoa() {
[native code]
} frameElement
function showModalDialog() {
[native code]
}
function postMessage() {
[native code]
}
function addEventListener() {
[native code]
} localStorage
0-Ð History.item 1 8X0 p
1
current-Ð History.current 1
previous-Ð History.previous 1
next-Ð History.next 1
function
back() {
[native code]
}
function forward() {
[native code]
}
function go() {
[native code]
}
function item() {
[native code]
}
history
1
navigator
Mozilla
Netscape
5.0 (Windows; ko)
ko mimeTypes
Win32
Windows
NT 5.1
Gecko
20100625 plugins
Mozilla/5.0
(Windows; U; Windows NT 5.1; ko; rv:1.9.2.6) Gecko/20100625
Firefox/3.6.6 ( .NET CLR 3.5.30729)
true
true
20100625231939
function
javaEnabled() {
[native code]
}
function taintEnabled() {
[native code]
}
function preference() {
[native code]
} geolocation
function registerContentHandler() {
[native code]
}
function registerProtocolHandler() {
[native code]
}
function mozIsLocallyAvailable() {
[native code]
}
navigator
Mozilla
Microsoft Internet
Explorer
0
x86
Win32 plugins opsProfile userProfile
ko
ko
4.0
(compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR
3.0.4506.2152; .NET CLR 3.5.30729)
Mozilla/4.0 (compatible; MSIE 8.0; Windows
NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR
3.5.30729)
true
true mimeTypes
문득 수직탭은 들어 본적은 있는데 머하는데 쓰고,
어떻게 출력이 되는지는 모른다는 깨달음(?)을 얻었다.
검색을 해봐도 이렇다할 결과가 없긴한데...
대충 추려내자면
예전에 리본/도트 프린터 시절에 제어를 위해 존재했었는데,
프린터에서 수평탭은 8칸, 수직탭은 6줄마다 이동하도록 되어있다고 한다.
하지만, Virtual Terminal 상에서 표현은 자율에 맡기다 보니,
이상한 문자가 출력되거나, 엔터 처럼 처리되는 경우가 많은것으로 보인다.
대충 리눅스 상에서 해보니 \v (vertical tab)은 LF의 느낌이 든다.
LF(Line Feed)는 지금의 위치에서 바로 아래로 내려지게 되고, CR(Carriage Return)은 가장 앞줄로 이동하게 된다.
(타자기를 생각하면 한글자씩 쓰다가 끝까지 치게 되면 왼쪽으로 미는데 그걸 CR이라고 보면되고
종이를 밀어서 한줄 아래로 내리는걸 LF라고 보면된다.)
The following control
codes are optional but should have the
indicated effect on the display.
Name
code
Decimal Value
Function
BELL
BEL
7
Produces an audible or visible signal (which does NOT
move the print head.
Back Space
BS
8
Moves the print head one character position towards the
left margin. [On a printing devices this mechanism was commonly used to
form composite characters by printing two basic characters on top of
each other.]
Horizontal
Tab
HT
9
Moves the printer to the next horizontal tab stop. It
remains unspecified how either party determines or establishes where
such tab stops are located.
Vertical
Tab
VT
11
Moves the printer to the next vertical tab stop. It
remains unspecified how either party determines or establishes where
such tab stops are located.
Form Feed
FF
12
Moves the printer to the top of the next page, keeping
the same horizontal position. [On visual displays this commonly clears
the screen and moves the cursor to the top left corner.]
vertical
tab (′vərd·ə·kəl ′tab)
(computer science) A control character that causes a computer
printer to jump
from its current line to another preset line further
down the page.
Originally
printers used mechanical tab stops to indicate where the tabs
went. This was done horizontally with movable metal prongs in a row and
vertically with a loop of mylar or other tape the length of a
page with holes punched in it to indicate the tab stops. Initially
these were manually set to match the preprinted forms the printer was
going to print. The intention was to have the machine be programmed with
other control characters to set and clear the stops: ISO 6429 includes the codes 136 Horizontal
Tabulation Set, 137 Horizontal Tabulation with Justification and 138
Vertical Tabulation Set.
Instead settable tab stops were rather quickly replaced with fixed
tab
stops, at
every multiple of 8 characters horizontally and every 6 lines
vertically. A printing program could easily add the necessary
spaces or
line feeds to move to any position wanted on a form, this was far more
reliable than the modal and non-standard
methods of setting tab stops. Tab characters simply became a form of
data compression. The vertical size was chosen to be 1 inch. It is
unclear why the 8-character horizontal size was chosen, as 5 characters,
half inch in a typical printer at that time, was much more popular at
that time as a paragraph indentation. It may have been chosen to match
early Fortran
conventions for where the statement text started after the line number
and continuation character. Or it may have been chosen as the smallest
size that would fit numbers typically printed in a table.
문자열 중에 확장 문자열이라는 게 있다. 대표적으로 \n 같은 경우인데 일종의 정해진 규약이다. 이 중에
수직탭이라는 게 있는데 \v
로 표현된다. C 언어 펀더멘탈 책을 보던 중 궁금증이 들어서 출력을 해보니 윈도우 콘솔 상에서는
이상한 특수문자를 하나 출력해주고 만다. 하지만 리눅스 콘솔에서 출력해보니 세로로 한 칸 내려가버린다. 즉 다음과 같은 결과를
보여준다.
null, a special keyword denoting a null value; null is also a primitive value.
Because JavaScript is case-sensitive, null is not the same as Null, NULL, or
any other variant l undefined, a top-level property whose value is undefined; undefined is also a primitive value