Skip to content

Instantly share code, notes, and snippets.

@tong9433
Last active July 12, 2017 00:26
Show Gist options
  • Save tong9433/4ee97fa8c30f561a759064539a795d45 to your computer and use it in GitHub Desktop.
Save tong9433/4ee97fa8c30f561a759064539a795d45 to your computer and use it in GitHub Desktop.
20170711과제

동적인 파라미터 처리

function myFunction(x, y) {
    y = y || 0;
}
// default 설정 

x = findMax(1, 123, 500, 115, 44, 88);

function findMax() {
    var i;
    var max = -Infinity;
    for (i = 0; i < arguments.length; i++) {
        if (arguments[i] > max) {
            max = arguments[i];
        }
    }
    return max;
}
// 추가 argument 다루는 방법

arguments 라는 객체가 생성되므로 이를 이용한다.

nodelist 배열처럼 쓰려면 어떻게 할지 2가지 방법

var nodesArray = Array.prototype.slice.call(document.querySelectorAll('div'));
var divs = document.querySelectorAll('div');
var arr = [];
for(var i = 0; i<divs.length;i++) arr.push(divs[i]);

innerHTML, insertAdjacentHTML 사용

var ul = document.querySelector("ul");
ul.insertAdjacentHTML('beforeend',"<li>melon</li>");

var li = document.querySelector("ul>li:nth-child(2)");
li.insertAdjacentHTML('afterend','<li>pineapple</li>');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment