차례
    1. 2.8 공통 DOM 인터페이스
      1. 2.8.1 IDL 속성에서 내용 속성의 반영
      2. 2.8.2 컬렉션
        1. 2.8.2.1 HTMLCollection
        2. 2.8.2.2 HTMLAllCollection
        3. 2.8.2.3 HTMLFormControlsCollection
        4. 2.8.2.4 HTMLOptionsCollection
      3. 2.8.3 DOMTokenList
      4. 2.8.4 DOMSettableTokenList
      5. 2.8.5 구조화된 데이터의 안전한 전달
      6. 2.8.6 DOMStringMap
      7. 2.8.7 DOM 기능 문자열
      8. 2.8.8 예외
      9. 2.8.9 메모리 반환

2.8 공통 DOM 인터페이스

2.8.1 IDL 속성에서 내용 속성의 반영

몇 가지 IDL 속성들은 특정한 내용 속성을 반영하도록 정의되었습니다. 이 말의 의미는, 가져올 때 IDL 속성은 내용 속성의 현재 값을 반환하며, 설정할 때 IDL 속성의 변화는 내용 속성의 값을 주어진 값을 변경함을 의미합니다.

Some IDL attributes are defined to reflect a particular content attribute. This means that on getting, the IDL attribute returns the current value of the content attribute, and on setting, the IDL attribute changes the value of the content attribute to the given value.

In general, on getting, if the content attribute is not present, the IDL attribute must act as if the content attribute's value is the empty string; and on setting, if the content attribute is not present, it must first be added.

If a reflecting IDL attribute is a DOMString attribute whose content attribute is defined to contain a URL, then on getting, the IDL attribute must resolve the value of the content attribute relative to the element and return the resulting absolute URL if that was successful, or the empty string otherwise; and on setting, must set the content attribute to the specified literal value. If the content attribute is absent, the IDL attribute must return the default value, if the content attribute has one, or else the empty string.

If a reflecting IDL attribute is a DOMString attribute whose content attribute is defined to contain one or more URLs, then on getting, the IDL attribute must split the content attribute on spaces and return the concatenation of resolving each token URL to an absolute URL relative to the element, with a single U+0020 SPACE character between each URL, ignoring any tokens that did not resolve successfully. If the content attribute is absent, the IDL attribute must return the default value, if the content attribute has one, or else the empty string. On setting, the IDL attribute must set the content attribute to the specified literal value.

If a reflecting IDL attribute is a DOMString whose content attribute is an enumerated attribute, and the IDL attribute is limited to only known values, then, on getting, the IDL attribute must return the conforming value associated with the state the attribute is in (in its canonical case), or the empty string if the attribute is in a state that has no associated keyword value; and on setting, the content attribute must be set to the specified new value.

If a reflecting IDL attribute is a DOMString but doesn't fall into any of the above categories, then the getting and setting must be done in a transparent, case-preserving manner.

If a reflecting IDL attribute is a boolean attribute, then on getting the IDL attribute must return true if the content attribute is set, and false if it is absent. On setting, the content attribute must be removed if the IDL attribute is set to false, and must be set to the empty string if the IDL attribute is set to true. (This corresponds to the rules for boolean content attributes.)

If a reflecting IDL attribute is a signed integer type (long) then, on getting, the content attribute must be parsed according to the rules for parsing signed integers, and if that is successful, and the value is in the range of the IDL attribute's type, the resulting value must be returned. If, on the other hand, it fails or returns an out of range value, or if the attribute is absent, then the default value must be returned instead, or 0 if there is no default value. On setting, the given value must be converted to the shortest possible string representing the number as a valid integer and then that string must be used as the new content attribute value.

If a reflecting IDL attribute is a signed integer type (long) that is limited to only non-negative numbers then, on getting, the content attribute must be parsed according to the rules for parsing non-negative integers, and if that is successful, and the value is in the range of the IDL attribute's type, the resulting value must be returned. If, on the other hand, it fails or returns an out of range value, or if the attribute is absent, the default value must be returned instead, or −1 if there is no default value. On setting, if the value is negative, the user agent must fire an INDEX_SIZE_ERR exception. Otherwise, the given value must be converted to the shortest possible string representing the number as a valid non-negative integer and then that string must be used as the new content attribute value.

If a reflecting IDL attribute is an unsigned integer type (unsigned long) then, on getting, the content attribute must be parsed according to the rules for parsing non-negative integers, and if that is successful, and the value is in the range 0 to 2147483647 inclusive, the resulting value must be returned. If, on the other hand, it fails or returns an out of range value, or if the attribute is absent, the default value must be returned instead, or 0 if there is no default value. On setting, the given value must be converted to the shortest possible string representing the number as a valid non-negative integer and then that string must be used as the new content attribute value.

If a reflecting IDL attribute is an unsigned integer type (unsigned long) that is limited to only non-negative numbers greater than zero, then the behavior is similar to the previous case, but zero is not allowed. On getting, the content attribute must first be parsed according to the rules for parsing non-negative integers, and if that is successful, and the value is in the range 1 to 2147483647 inclusive, the resulting value must be returned. If, on the other hand, it fails or returns an out of range value, or if the attribute is absent, the default value must be returned instead, or 1 if there is no default value. On setting, if the value is zero, the user agent must fire an INDEX_SIZE_ERR exception. Otherwise, the given value must be converted to the shortest possible string representing the number as a valid non-negative integer and then that string must be used as the new content attribute value.

If a reflecting IDL attribute is a floating point number type (double), then, on getting, the content attribute must be parsed according to the rules for parsing floating point number values, and if that is successful, the resulting value must be returned. If, on the other hand, it fails, or if the attribute is absent, the default value must be returned instead, or 0.0 if there is no default value. On setting, the given value must be converted to the best representation of the number as a floating point number and then that string must be used as the new content attribute value.

The values Infinity and Not-a-Number (NaN) values throw an exception on setting, as defined earlier.

If a reflecting IDL attribute is of the type DOMTokenList or DOMSettableTokenList, then on getting it must return a DOMTokenList or DOMSettableTokenList object (as appropriate) whose underlying string is the element's corresponding content attribute. When the object mutates its underlying string, the content attribute must itself be immediately mutated. When the attribute is absent, then the string represented by the object is the empty string; when the object mutates this empty string, the user agent must add the corresponding content attribute, with its value set to the value it would have been set to after mutating the empty string. The same DOMTokenList or DOMSettableTokenList object must be returned every time for each attribute.

If an element with no attributes has its element.classList.remove() method invoked, the underlying string won't be changed, since the result of removing any token from the empty string is still the empty string. However, if the element.classList.add() method is then invoked, a class attribute will be added to the element with the value of the token to be added.

If a reflecting IDL attribute has the type HTMLElement, or an interface that descends from HTMLElement, then, on getting, it must run the following algorithm (stopping at the first point where a value is returned):

  1. If the corresponding content attribute is absent, then the IDL attribute must return null.
  2. Let candidate be the element that the document.getElementById() method would find when called on the content attribute's document if it was passed as its argument the current value of the corresponding content attribute.
  3. If candidate is null, or if it is not type-compatible with the IDL attribute, then the IDL attribute must return null.
  4. Otherwise, it must return candidate.

On setting, if the given element has an id attribute, then the content attribute must be set to the value of that id attribute. Otherwise, the IDL attribute must be set to the empty string.

2.8.2 컬렉션

HTMLCollection, HTMLAllCollection, HTMLFormControlsCollection, HTMLOptionsCollection은 DOM 노드들의 다양한 목록을 나타내는 인터페이스입니다. 수집한다는 의미로, 이러한 인터페이스를 구현하는 객체들을 컬렉션이라 부릅니다.

The HTMLCollection, HTMLAllCollection, HTMLFormControlsCollection, HTMLOptionsCollection, interfaces represent various lists of DOM nodes. Collectively, objects implementing these interfaces are called collections.

컬렉션이 생성될 때, 필터와 루트가 컬렉션과 연결됩니다.

When a collection is created, a filter and a root are associated with the collection.

예를 들어, document.images 속성에 대한 HTMLCollection 객체가 생성될 때, 그것은 오직 img 요소만을 선택하는 필터와 연결되며, 문서의 루트에 뿌리를 두게 됩니다.

For example, when the HTMLCollection object for the document.images attribute is created, it is associated with a filter that selects only img elements, and rooted at the root of the document.

다음, 컬렉션은 컬렉션의 루트에 뿌리를 둔, 오직 필터에 일치하는 노드들만을 포함하는 서브트리의 살아있는 뷰 를 나타냅니다. 이 뷰 는 선형입니다.

The collection then represents a live view of the subtree rooted at the collection's root, containing only nodes that match the given filter. The view is linear. In the absence of specific requirements to the contrary, the nodes within the collection must be sorted in tree order.

The rows list is not in tree order.

An attribute that returns a collection must return the same object every time it is retrieved.

2.8.2.1 HTMLCollection

HTMLCollection 인터페이스는 요소들에 대한 범용 컬렉션을 나타냅니다.

The HTMLCollection interface represents a generic collection of elements.

interface HTMLCollection {
  readonly attribute unsigned long length;
  caller getter Element item(in unsigned long index);
  caller getter object namedItem(in DOMString name); // only returns Element
};
collection . length

컬렉션에 포함된 요소의 숫자를 반환합니다.

Returns the number of elements in the collection.

element = collection . item(index)
collection[index]
collection(index)

index에 해당하는 아이템을 반환합니다. 아이템은 트리 순서로 정렬됩니다.

Returns the item with index index from the collection. The items are sorted in tree order.

index가 범위를 벗어나면 null을 반환합니다.

Returns null if index is out of range.

element = collection . namedItem(name)
collection[name]
collection(name)

name에 해당하는 이름, 또는 ID를 가진 첫 번째 아이템을 반환합니다.

Returns the first item with ID or name name from the collection.

그러한 아이템을 찾을 수 없다면 null을 반환합니다.

Returns null if no element with that ID or name could be found.

a, applet, area, embed, form, frame, frameset, iframe, img, object 요소만 이러한 메서드에 해당하는 이름을 가질 수 있습니다. 그러한 이름은 name 속성으로 주어집니다.

Only a, applet, area, embed, form, frame, frameset, iframe, img, and object elements can have a name for the purpose of this method; their name is given by the value of their name attribute.

The object's supported property indices are the numbers in the range zero to one less than the number of nodes represented by the collection. If there are no such elements, then there are no supported property indices.

The length attribute must return the number of nodes represented by the collection.

The item(index) method must return the indexth node in the collection. If there is no indexth node in the collection, then the method must return null.

The supported property names consist of the values of the name attributes of each a, applet, area, embed, form, frame, frameset, iframe, img, and object element represented by the collection with a name attribute, plus the list of IDs that the elements represented by the collection have.

The namedItem(key) method must return the first node in the collection that matches the following requirements:

If no such elements are found, then the method must return null.

2.8.2.2 HTMLAllCollection

HTMLAllCollection 인터페이스는 HTMLCollection과 같이 요소의 범용 컬렉션을 나타냅니다만, 그것의 namedItem() 메서드는 일치하는 것이 여럿일 경우 HTMLCollection 객체를 반환합니다.

The HTMLAllCollection interface represents a generic collection of elements just like HTMLCollection, with the exception that its namedItem() method returns an HTMLAllCollection object when there are multiple matching elements.

interface HTMLAllCollection : HTMLCollection {
  // inherits length and item()
  caller getter object namedItem(in DOMString name); // overrides inherited namedItem()
  HTMLAllCollection tags(in DOMString tagName);
};
collection . length

컬렉션에 포함된 요소의 숫자를 반환합니다.

Returns the number of elements in the collection.

element = collection . item(index)
collection[index]
collection(index)

index에 해당하는 아이템을 반환합니다. 아이템은 트리 순서로 정렬됩니다.

Returns the item with index index from the collection. The items are sorted in tree order.

index가 범위를 벗어나면 null을 반환합니다.

Returns null if index is out of range.

element = collection . namedItem(name)
collection = collection . namedItem(name)
collection[name]
collection(name)

name에 해당하는 ID, 혹은 이름을 갖는 아이템을 반환합니다.

Returns the item with ID or name name from the collection.

일치하는 아이템이 여럿일 경우, 그러한 모든 요소를 포함하는 HTMLAllCollection 객체를 반환합니다.

If there are multiple matching items, then an HTMLAllCollection object containing all those elements is returned.

일치하는 것이 없으면 null을 반환합니다.

Returns null if no element with that ID or name could be found.

a, applet, area, embed, form, frame, frameset, iframe, img, object 요소만 이러한 메서드에 해당하는 이름을 가질 수 있습니다. 그러한 이름은 name 속성으로 주어집니다.

Only a, applet, area, embed, form, frame, frameset, iframe, img, and object elements can have a name for the purpose of this method; their name is given by the value of their name attribute.

collection = collection . tags(tagName)

현재의 컬렉션에 대한 필터된 뷰 를 반환합니다. 주어진 태그 이름을 갖는 요소들만을 포함합니다.

Returns a collection that is a filtered view of the current collection, containing only elements with the given tag name.

The object's supported property indices and supported property names are as defined for HTMLCollection objects.

The namedItem(key) method must act according to the following algorithm:

  1. Let collection be an HTMLAllCollection object rooted at the same node as the HTMLAllCollection object on which the method was invoked, whose filter matches only elements that already match the filter of the HTMLAllCollection object on which the method was invoked and that are either:

  2. If, at the time the method is called, there is exactly one node in collection, then return that node and stop the algorithm.
  3. Otherwise, if, at the time the method is called, collection is empty, return null and stop the algorithm.
  4. Otherwise, return collection.

The tags(tagName) method must return an HTMLAllCollection rooted at the same node as the HTMLAllCollection object on which the method was invoked, whose filter matches only HTML elements whose local name is the tagName argument and that already match the filter of the HTMLAllCollection object on which the method was invoked. In HTML documents, the argument must first be converted to ASCII lowercase.

2.8.2.3 HTMLFormControlsCollection

HTMLFormControlsCollection 인터페이스는 form, fieldset 요소 내의 요소 목록의 컬렉션을 나타냅니다.

The HTMLFormControlsCollection interface represents a collection of listed elements in form and fieldset elements.

interface HTMLFormControlsCollection : HTMLCollection {
  // inherits length and item()
  caller getter object namedItem(in DOMString name); // overrides inherited namedItem()
};

interface RadioNodeList : NodeList {
          attribute DOMString value;
};
collection . length

컬렉션에 포함된 요소의 숫자를 반환합니다.

Returns the number of elements in the collection.

element = collection . item(index)
collection[index]
collection(index)

index에 해당하는 아이템을 반환합니다. 아이템은 트리 순서로 정렬됩니다.

Returns the item with index index from the collection. The items are sorted in tree order.

index가 범위를 벗어난 경우 null을 반환합니다.

Returns null if index is out of range.

element = collection . namedItem(name)
radioNodeList = collection . namedItem(name)
collection[name]
collection(name)

name에 해당하는 ID, 또는 name을 가진 아이템을 반환합니다.

Returns the item with ID or name name from the collection.

해당하는 아이템이 여럿인 경우, 그러한 모든 요소를 포함하는 RadioNodeList 객체를 반환합니다.

If there are multiple matching items, then a RadioNodeList object containing all those elements is returned.

해당하는 아이템이 없다면 null을 반환합니다.

Returns null if no element with that ID or name could be found.

radioNodeList . value [ = value ]

객체가 나타내는 첫 번째 체크된 라디오 버튼의 값을 반환합니다.

Returns the value of the first checked radio button represented by the object.

그러한 버튼을 체크하기 위해 설정할 수 있습니다.

Can be set, to check the first radio button with the given value represented by the object.

The object's supported property indices are as defined for HTMLCollection objects.

The supported property names consist of the values of all the id and name attributes of all the elements represented by the collection.

The namedItem(name) method must act according to the following algorithm:

  1. If, at the time the method is called, there is exactly one node in the collection that has either an id attribute or a name attribute equal to name, then return that node and stop the algorithm.
  2. Otherwise, if there are no nodes in the collection that have either an id attribute or a name attribute equal to name, then return null and stop the algorithm.
  3. Otherwise, create a new RadioNodeList object representing a live view of the HTMLFormControlsCollection object, further filtered so that the only nodes in the RadioNodeList object are those that have either an id attribute or a name attribute equal to name. The nodes in the RadioNodeList object must be sorted in tree order.
  4. Return that RadioNodeList object.

Members of the RadioNodeList interface inherited from the NodeList interface must behave as they would on a NodeList object.

The value IDL attribute on the RadioNodeList object, on getting, must return the value returned by running the following steps:

  1. Let element be the first element in tree order represented by the RadioNodeList object that is an input element whose type attribute is in the Radio Button state and whose checkedness is true. Otherwise, let it be null.

  2. If element is null, or if it is an element with no value attribute, return the empty string.

  3. Otherwise, return the value of element's value attribute.

On setting, the value IDL attribute must run the following steps:

  1. Let element be the first element in tree order represented by the RadioNodeList object that is an input element whose type attribute is in the Radio Button state and whose value content attribute is present and equal to the new value, if any. Otherwise, let it be null.

  2. If element is not null, then set its checkedness to true.

2.8.2.4 HTMLOptionsCollection

HTMLOptionsCollection 인터페이스는 option 요소의 목록을 나타냅니다. 이것은 언제나 select 요소에 뿌리를 두며, 요소의 자손을 조작하는 속성과 메서드를 가집니다.

The HTMLOptionsCollection interface represents a list of option elements. It is always rooted on a select element and has attributes and methods that manipulate that element's descendants.

interface HTMLOptionsCollection : HTMLCollection {
  // inherits item()
           attribute unsigned long length; // overrides inherited length
  caller getter object namedItem(in DOMString name); // overrides inherited namedItem()
  void add(in HTMLElement element, in optional HTMLElement before);
  void add(in HTMLElement element, in long before);
  void remove(in long index);
           attribute long selectedIndex;
};
collection . length [ = value ]

컬렉션에 포함된 요소들의 숫자를 반환합니다.

Returns the number of elements in the collection.

더 적은 숫자로 설정되면, 해당하는 컨테이너에 포함된 option 요소를 버립니다.

When set to a smaller number, truncates the number of option elements in the corresponding container.

더 큰 숫자로 설정되면, 컨테이너에 비어 있는 option 요소를 추가합니다.

When set to a greater number, adds new blank option elements to that container.

element = collection . item(index)
collection[index]
collection(index)

컬렉션에서 index 번째 아이템을 반환합니다. 아이템은 트리 순서로 정렬됩니다.

Returns the item with index index from the collection. The items are sorted in tree order.

index가 범위를 벗어나면 null을 반환합니다.

Returns null if index is out of range.

element = collection . namedItem(name)
nodeList = collection . namedItem(name)
collection[name]
collection(name)

name 에 해당하는 ID 또는 name을 가진 아이템을 반환합니다.

Returns the item with ID or name name from the collection.

해당하는 아이템이 여럿이라면, 그러한 모든 요소를 포함하는 NodeList 객체를 반환합니다.

If there are multiple matching items, then a NodeList object containing all those elements is returned.

해당하는 요소가 없다면 null을 반환합니다.

Returns null if no element with that ID could be found.

collection . add(element [, before ] )

element요소를 before 노드 앞에 삽입합니다.

Inserts element before the node given by before.

before 매개변수는 숫자가 될 수 있습니다. 그러면 element 요소는 숫자에 해당하는 아이템 앞에 삽입됩니다. before가 컬렉션에 포함된 요소일 경우, element는 그 요소 앞에 삽입됩니다.

The before argument can be a number, in which case element is inserted before the item with that number, or an element from the collection, in which case element is inserted before that element.

before가 생략되었거나 범위를 벗어나면, element는 목록의 마지막에 추가됩니다.

If before is omitted, null, or a number out of range, then element will be added at the end of the list.

이 메서드는 element가 자신이 삽입될 요소의 조상에 해당하면 HIERARCHY_REQUEST_ERR 예외를 반환합니다. elementoption 요소, 혹은 optgroup 요소가 아니면 메서드는 아무 일도 하지 않습니다.

This method will throw a HIERARCHY_REQUEST_ERR exception if element is an ancestor of the element into which it is to be inserted. If element is not an option or optgroup element, then the method does nothing.

collection . selectedIndex [ = value ]

첫 번째로 선택된 아이템의 인덱스를 반환합니다. 선택된 것이 없다면 -1을 반환합니다.

Returns the index of the first selected item, if any, or −1 if there is no selected item.

설정하여, 선택된 것을 바꿀 수 있습니다.

Can be set, to change the selection.

The object's supported property indices are as defined for HTMLCollection objects.

On getting, the length attribute must return the number of nodes represented by the collection.

On setting, the behavior depends on whether the new value is equal to, greater than, or less than the number of nodes represented by the collection at that time. If the number is the same, then setting the attribute must do nothing. If the new value is greater, then n new option elements with no attributes and no child nodes must be appended to the select element on which the HTMLOptionsCollection is rooted, where n is the difference between the two numbers (new value minus old value). Mutation events must be fired as if a DocumentFragment containing the new option elements had been inserted. If the new value is lower, then the last n nodes in the collection must be removed from their parent nodes, where n is the difference between the two numbers (old value minus new value).

Setting length never removes or adds any optgroup elements, and never adds new children to existing optgroup elements (though it can remove children from them).

The supported property names consist of the values of all the id and name attributes of all the elements represented by the collection.

The namedItem(name) method must act according to the following algorithm:

  1. If, at the time the method is called, there is exactly one node in the collection that has either an id attribute or a name attribute equal to name, then return that node and stop the algorithm.
  2. Otherwise, if there are no nodes in the collection that have either an id attribute or a name attribute equal to name, then return null and stop the algorithm.
  3. Otherwise, create a new NodeList object representing a live view of the HTMLOptionsCollection object, further filtered so that the only nodes in the NodeList object are those that have either an id attribute or a name attribute equal to name. The nodes in the NodeList object must be sorted in tree order.
  4. Return that NodeList object.

The add(element, before) method must act according to the following algorithm:

  1. If element is not an option or optgroup element, then return and abort these steps.

  2. If element is an ancestor of the select element on which the HTMLOptionsCollection is rooted, then throw a HIERARCHY_REQUEST_ERR exception.

  3. If before is an element, but that element isn't a descendant of the select element on which the HTMLOptionsCollection is rooted, then throw a NOT_FOUND_ERR exception.

  4. If element and before are the same element, then return and abort these steps.

  5. If before is a node, then let reference be that node. Otherwise, if before is an integer, and there is a beforeth node in the collection, let reference be that node. Otherwise, let reference be null.

  6. If reference is not null, let parent be the parent node of reference. Otherwise, let parent be the select element on which the HTMLOptionsCollection is rooted.

  7. Act as if the DOM Core insertBefore() method was invoked on the parent node, with element as the first argument and reference as the second argument.

The remove(index) method must act according to the following algorithm:

  1. If the number of nodes represented by the collection is zero, abort these steps.

  2. If index is not a number greater than or equal to 0 and less than the number of nodes represented by the collection, let element be the first element in the collection. Otherwise, let element be the indexth element in the collection.

  3. Remove element from its parent node.

The selectedIndex IDL attribute must act like the identically named attribute on the select element on which the HTMLOptionsCollection is rooted

DOMTokenList 인터페이스는 공백문자로 구분된 토큰의 목록을 구성하는 문자열에 대한 인터페이스를 나타냅니다.

The DOMTokenList interface represents an interface to an underlying string that consists of a set of space-separated tokens.

DOMTokenList 객체는 언제나 대소문자를 구분합니다. 이것은 설령 반영되는 문자열이 대소문자를 구분하지 않는 것이라 해도 그렇습니다.

DOMTokenList objects are always case-sensitive, even when the underlying string might ordinarily be treated in a case-insensitive manner.

interface DOMTokenList {
  readonly attribute unsigned long length;
  getter DOMString item(in unsigned long index);
  boolean contains(in DOMString token);
  void add(in DOMString token);
  void remove(in DOMString token);
  boolean toggle(in DOMString token);
  stringifier DOMString ();
};
tokenlist . length

문자열에 포함된 토큰의 숫자를 반환합니다.

Returns the number of tokens in the string.

element = tokenlist . item(index)
tokenlist[index]

index에 해당하는 토큰을 반환합니다. 토큰은 반영된 문자열에서 발견되는 순서로 정렬됩니다.

Returns the token with index index. The tokens are returned in the order they are found in the underlying string.

index가 범위를 벗어나면 null을 반환합니다.

Returns null if index is out of range.

hastoken = tokenlist . contains(token)

token이 있으면 참을 반환합니다.

Returns true if the token is present; false otherwise.

token이 비어 있다면 SYNTAX_ERR 예외를 반환합니다.

Throws a SYNTAX_ERR exception if token is empty.

token이 공백문자를 포함한다면 INVALID_CHARACTER_ERR 예외를 반환합니다.

Throws an INVALID_CHARACTER_ERR exception if token contains any spaces.

tokenlist . add(token)

token이 이미 존재하지 않는다면 그것을 추가합니다.

Adds token, unless it is already present.

token이 비어 있다면 SYNTAX_ERR 예외를 반환합니다.

Throws a SYNTAX_ERR exception if token is empty.

token이 공백문자를 포함한다면 INVALID_CHARACTER_ERR 예외를 반환합니다.

Throws an INVALID_CHARACTER_ERR exception if token contains any spaces.

tokenlist . remove(token)

token이 이미 존재한다면 그것을 제거합니다.

Removes token if it is present.

token이 비어 있다면 SYNTAX_ERR 예외를 반환합니다.

Throws a SYNTAX_ERR exception if token is empty.

token이 공백문자를 포함한다면 INVALID_CHARACTER_ERR 예외를 반환합니다.

Throws an INVALID_CHARACTER_ERR exception if token contains any spaces.

hastoken = tokenlist . toggle(token)

Adds token이 존재하지 않는다면 추가하고, 존재한다면 그것을 제거합니다. 현재 token이 있다면 참을 반환하고(추가된 것입니다.); 그렇지 않다면 거짓을 반환합니다. (제거된 것입니다.).

Adds token if it is not present, or removes it if it is. Returns true if token is now present (it was added); returns false if it is not (it was removed).

token이 비어 있다면 SYNTAX_ERR 예외를 반환합니다.

Throws a SYNTAX_ERR exception if token is empty.

token이 공백문자를 포함한다면 INVALID_CHARACTER_ERR 예외를 반환합니다.

Throws an INVALID_CHARACTER_ERR exception if token contains any spaces.

The length attribute must return the number of tokens that result from splitting the underlying string on spaces. This is the length.

The object's supported property indices are the numbers in the range zero to length-1, unless the length is zero, in which case there are no supported property indices.

The item(index) method must split the underlying string on spaces, preserving the order of the tokens as found in the underlying string, and then return the indexth item in this list. If index is equal to or greater than the number of tokens, then the method must return null.

For example, if the string is "a b a c" then there are four tokens: the token with index 0 is "a", the token with index 1 is "b", the token with index 2 is "a", and the token with index 3 is "c".

The contains(token) method must run the following algorithm:

  1. If the token argument is the empty string, then raise a SYNTAX_ERR exception and stop the algorithm.
  2. If the token argument contains any space characters, then raise an INVALID_CHARACTER_ERR exception and stop the algorithm.
  3. Otherwise, split the underlying string on spaces to get the list of tokens in the object's underlying string.
  4. If the token indicated by token is a case-sensitive match for one of the tokens in the object's underlying string then return true and stop this algorithm.
  5. Otherwise, return false.

The add(token) method must run the following algorithm:

  1. If the token argument is the empty string, then raise a SYNTAX_ERR exception and stop the algorithm.
  2. If the token argument contains any space characters, then raise an INVALID_CHARACTER_ERR exception and stop the algorithm.
  3. Otherwise, split the underlying string on spaces to get the list of tokens in the object's underlying string.
  4. If the given token is a case-sensitive match for one of the tokens in the DOMTokenList object's underlying string then stop the algorithm.
  5. Otherwise, if the DOMTokenList object's underlying string is not the empty string and the last character of that string is not a space character, then append a U+0020 SPACE character to the end of that string.
  6. Append the value of token to the end of the DOMTokenList object's underlying string.

The remove(token) method must run the following algorithm:

  1. If the token argument is the empty string, then raise a SYNTAX_ERR exception and stop the algorithm.
  2. If the token argument contains any space characters, then raise an INVALID_CHARACTER_ERR exception and stop the algorithm.
  3. Otherwise, remove the given token from the underlying string.

The toggle(token) method must run the following algorithm:

  1. If the token argument is the empty string, then raise a SYNTAX_ERR exception and stop the algorithm.
  2. If the token argument contains any space characters, then raise an INVALID_CHARACTER_ERR exception and stop the algorithm.
  3. Otherwise, split the underlying string on spaces to get the list of tokens in the object's underlying string.
  4. If the given token is a case-sensitive match for one of the tokens in the DOMTokenList object's underlying string then remove the given token from the underlying string and stop the algorithm, returning false.
  5. Otherwise, if the DOMTokenList object's underlying string is not the empty string and the last character of that string is not a space character, then append a U+0020 SPACE character to the end of that string.
  6. Append the value of token to the end of the DOMTokenList object's underlying string.
  7. Return true.

Objects implementing the DOMTokenList interface must stringify to the object's underlying string representation.

2.8.4 DOMSettableTokenList

DOMSettableTokenList 인터페이스는 DOMTokenList 인터페이스와 같지만, 반영하는 문자열이 직접 변경될 수 있다는 점에서 다릅니다.

The DOMSettableTokenList interface is the same as the DOMTokenList interface, except that it allows the underlying string to be directly changed.

interface DOMSettableTokenList : DOMTokenList {
            attribute DOMString value;
};
tokenlist . value

반영하는 문자열을 반환합니다.

Returns the underlying string.

문자열을 변경하기 위해 설정할 수 있습니다.

Can be set, to change the underlying string.

An object implementing the DOMSettableTokenList interface must act as defined for the DOMTokenList interface, except for the value attribute defined here.

The value attribute must return the underlying string on getting, and must replace the underlying string with the new value on setting.

2.8.5 구조화된 데이터의 안전한 전달

When a user agent is required to obtain a structured clone of an object, it must run the following algorithm, which either returns a separate object, or throws an exception.

  1. Let input be the object being cloned.

  2. Let memory be an association list of pairs of objects, initially empty. This is used to handle duplicate references. In each pair of objects, one is called the source object and the other the destination object.

  3. Let output be the object resulting from calling the internal structured cloning algorithm with input and memory.

  4. Return output.

The internal structured cloning algorithm is always called with two arguments, input and memory, and its behavior is as follows:

  1. If input is the source object of a pair of objects in memory, then return the destination object in that pair of objects and abort these steps.

  2. If input is a primitive value, then return that value and abort these steps.

  3. The input value is an object. Jump to the appropriate step below:

    If input is a Boolean object

    Let output be a newly constructed Boolean object with the same value as input.

    If input is a Number object

    Let output be a newly constructed Number object with the same value as input.

    If input is a String object

    Let output be a newly constructed String object with the same value as input.

    If input is a Date object

    Let output be a newly constructed Date object with the same value as input.

    If input is a RegExp object

    Let output be a newly constructed RegExp object with the same pattern and flags as input.

    The value of the lastIndex property is not copied.

    If input is a ImageData object

    Let output be a newly constructed ImageData object with the same width and height as input, and with a newly constructed CanvasPixelArray for its data attribute, with the same length and pixel values as the input's.

    If input is a File object

    Let output be a newly constructed File object corresponding to the same underlying data.

    If input is a Blob object

    Let output be a newly constructed Blob object corresponding to the same underlying data.

    If input is a FileList object

    Let output be a newly constructed FileList object containing a list of newly constructed File objects corresponding to the same underlying data as those in input, maintaining their relative order.

    If input is an Array object

    Let output be a newly constructed empty Array object.

    If input is an Object object

    Let output be a newly constructed empty Object object.

    If input is another native object type (e.g. Error, Function)
    If input is a host object (e.g. a DOM node)

    Throw a DATA_CLONE_ERR exception and abort the overall structured clone algorithm.

  4. Add a mapping from input (the source object) to output (the destination object) to memory.

  5. If input is an Array object or an Object object, then, for each enumerable property in input, add a corresponding property to output having the same name, and having a value created from invoking the internal structured cloning algorithm recursively with the value of the property as the "input" argument and memory as the "memory" argument. The order of the properties in the input and output objects must be the same.

    This does not walk the prototype chain.

  6. Return output.

This algorithm preserves cycles and preserves the identity of duplicate objects in graphs.

2.8.6 DOMStringMap

DOMStringMap 인터페이스는 이름-값 쌍의 집합을 나타냅니다. 스크립팅 언어의 네이티브 메커니즘을 통해 프로퍼티에 접근하여 그것을 노출합니다.

The DOMStringMap interface represents a set of name-value pairs. It exposes these using the scripting language's native mechanisms for property access.

When a DOMStringMap object is instantiated, it is associated with three algorithms, one for getting the list of name-value pairs, one for setting names to certain values, and one for deleting names.

interface DOMStringMap {
  getter DOMString (in DOMString name);
  setter void (in DOMString name, in DOMString value);
  creator void (in DOMString name, in DOMString value);
  deleter void (in DOMString name);
};

The supported property names on a DOMStringMap object at any instant are the names of each pair returned from the algorithm for getting the list of name-value pairs at that instant.

To determine the value of a named property name in a DOMStringMap, the user agent must return the value component of the name-value pair whose name component is name in the list returned by the algorithm for getting the list of name-value pairs.

To set the value of a new or existing named property name to value value, the algorithm for setting names to certain values must be run, passing name as the name and the result of converting value to a DOMString as the value.

To delete an existing named property name, the algorithm for deleting names must be run, passing name as the name.

The DOMStringMap interface definition here is only intended for JavaScript environments. Other language bindings will need to define how DOMStringMap is to be implemented for those languages.

dataset 속성은 요소의 data-* 속성을 노출합니다.

The dataset attribute on elements exposes the data-* attributes on the element.

다음의 마크업과 흡사한 구조를 살펴본다면:

Given the following fragment and elements with similar constructions:

<img class="tower" id="tower5" data-x="12" data-y="5"
     data-ai="robotarget" data-hp="46" data-ability="flames"
     src="towers/rocket.png" alt="Rocket Tower">

몇 가지 매개변수를 받는 함수 splashDamage() 를 상상할 수 있을 것입니다. 그중 첫 번째 매개변수는 처리해야 할 요소일 것입니다.

...one could imagine a function splashDamage() that takes some arguments, the first of which is the element to process:

function splashDamage(node, x, y, damage) {
  if (node.classList.contains('tower') && // checking the 'class' attribute
      node.dataset.x == x && // reading the 'data-x' attribute
      node.dataset.y == y) { // reading the 'data-y' attribute
    var hp = parseInt(node.dataset.hp); // reading the 'data-hp' attribute
    hp = hp - damage;
    if (hp < 0) {
      hp = 0;
      node.dataset.ai = 'dead'; // setting the 'data-ai' attribute
      delete node.dataset.ability; // removing the 'data-ability' attribute
    }
    node.dataset.hp = hp; // setting the 'data-hp' attribute
  }
}

2.8.7 DOM 기능 문자열

DOM3 코어는 인터페이스를 지원하는지 체크하고, 인터페이스 구현을 얻기 위한 메커니즘을 제공합니다. 이러한 메커니즘은 feature 문자열을 사용합니다. [DOMCORE]

DOM3 Core defines mechanisms for checking for interface support, and for obtaining implementations of interfaces, using feature strings. [DOMCORE]

이러한 것을 사용하지 않기를 강력히 권장합니다. 이것은 믿을 수 없고 부정확하기로 악명이 높습니다. 대신에 명시적인 기능 테스트에 의존하거나, 단계적 기능 축소 접근법을 사용하기를 권합니다.

Authors are strongly discouraged from using these, as they are notoriously unreliable and imprecise. Authors are encouraged to rely on explicit feature testing or the graceful degradation behavior intrinsic to some of the features in this specification.

For historical reasons, user agents should return the true value when the hasFeature(feature, version) method of the DOMImplementation interface is invoked with feature set to either "HTML" or "XHTML" and version set to either "1.0" or "2.0".

2.8.8 예외

The following are DOMException codes. [DOMCORE]

  1. INDEX_SIZE_ERR

  2. DOMSTRING_SIZE_ERR

  3. HIERARCHY_REQUEST_ERR

  4. WRONG_DOCUMENT_ERR

  5. INVALID_CHARACTER_ERR

  6. NO_DATA_ALLOWED_ERR

  7. NO_MODIFICATION_ALLOWED_ERR

  8. NOT_FOUND_ERR

  9. NOT_SUPPORTED_ERR

  10. INUSE_ATTRIBUTE_ERR

  11. INVALID_STATE_ERR

  12. SYNTAX_ERR

  13. INVALID_MODIFICATION_ERR

  14. NAMESPACE_ERR

  15. INVALID_ACCESS_ERR

  16. VALIDATION_ERR

  17. TYPE_MISMATCH_ERR

  18. SECURITY_ERR

  19. NETWORK_ERR

  20. ABORT_ERR

  21. URL_MISMATCH_ERR

  22. QUOTA_EXCEEDED_ERR

  23. TIMEOUT_ERR

  24. NOT_READABLE_ERR

  25. DATA_CLONE_ERR

  26. ENCODING_ERR

[Supplemental] exception DOMException {
  const unsigned short URL_MISMATCH_ERR = 21;
  const unsigned short QUOTA_EXCEEDED_ERR = 22;
  const unsigned short DATA_CLONE_ERR = 25;
};

2.8.9 메모리 반환

There is an implied strong reference from any IDL attribute that returns a pre-existing object to that object.

For example, the document.location attribute means that there is a strong reference from a Document object to its Location object. Similarly, there is always a strong reference from a Document to any descendant nodes, and from any node to its owner Document.