DOM 요소의 속성 그룹을 어떻게 자동화 할 수 있는지 궁금합니다. 나는 다음과 같이 작동하지만 코드가 무슨 뜻인지 이해를 참조하지 않습니다 알고기본 속성 (jQuery 없음)으로 구성된 JS에서 개체 생성자 만들기
function interface(bg, color, size, margin, content) {
this.style.backgroundColor=bg; //native html properties
this.style.color= last;
this.style.fontSize = size;
this.style.marginLeft = margin;
this.innerHTML=content;
}
var Green = new interface("green", "white", "20px", "20", "the green one");
var Blu = new interface("blue", "white", "48px", "0", "the blue one");
document.getElementById("demo").interface = Green;
그래야 속성의 그룹들을 다시 하나 하나를 가리 키도록하지 않고 적용됩니다. 완전히 벗어 났습니까?
속성을 반복하여 복사하십시오. 다양한 라이브러리가 이러한 기능을 구현하므로 직접 작성하거나 표준 ['Object.assign'] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/)을 사용하는 것이 쉽습니다. 개체/할당). 'style'을 적절히 다루기 위해서는 "deep extension"기능이 필요할 수도 있습니다. –
@FelixKling이 시점에서'Object.assign' "standard"를 호출하는 것이 정확한지 확신 할 수 없습니다. – JLRishe
@JLRishe : ECMAScript 6의 일부입니다. 얼마나 더 표준이 될 수 있습니까? –