왓챠 예제
셔플 함수
// 배열의 아이템을 뒤섞어서 새로운 배열 반환 var shuffle = function (array) { return array.slice().sort(function () { return Math.random() - 0.5; }); };


동적으로 스타일 규칙 추가하는 함수
공부 메모
Last updated
// 배열의 아이템을 뒤섞어서 새로운 배열 반환
var shuffle = function (array) {
return array.slice().sort(function () {
return Math.random() - 0.5;
});
};

Last updated
var insertStyleRules = (function (style) {
"use strict";
var sheet = document.head.appendChild(style).sheet;
// 클로저 함수
return function (selector, rules) {
var cssRulesString = Object.keys(rules)
.map(function (key) {
var value = rules[key];
return key + ":" + value;
})
.join(";");
sheet.insertRule(
selector + "{" + cssRulesString + "}",
sheet.cssRules.length
);
};
})(document.createElement("style")); // <style></style>