1
Node
생성자 함수에 연결하고 싶습니다. 공개 Node 생성자를 자신의 Node 생성자로 덮어 쓸 수 있습니까? 크롬HTMLNode 인터페이스 덮어 쓰기
현재는 테스트/파이어 폭스
(function() {
var _Node = window.Node;
var Node = function() {
Event.trigger("nodeCreation", this, arguments); // pseudocode
_Node.apply(this, arguments);
}
window.Node = Node;
console.log(document.createElement("div") instanceof _Node); // true
console.log(document.createElement("div") instanceof Node); // false
}());
나는 내가 오해하는 경우이가 얼마나 위험한 완벽하게 알고 있어요. 나는 그것이 올바르게 할 수 있다면 이것이 강력하게 다용도라는 것을 알고 있습니다.
원시 DOM 객체를 덮어 쓸 수있는 다른 방법이 있습니까? 프로토 타입을 확장하는 것은 생성자를 덮어 쓸 때 유용하지 않습니다.
dom traversal과 관련된 대안을 피하기 위해'document.createElement'에 연결하려고했습니다. – Raynos
최소한 Webkit 기반 브라우저에서는이 기능을 사용할 수 있습니다 (다른 기능과 함께 테스트하지 않았습니다) : document.crotteElement = document.createElement; document.createElement = function (x) {console.log ('Creating'+ x); this.crotteElement (x)}를 반환합니다. – jcayzac