What is the DOM / Wrapping extension?

I have two main questions.

  • Are things like Object count distributed?

  • What is a DOM package?

http://perfectionkills.com/whats-wrong-with-extending-the-dom/

After reading this article, I could not find anything about the DOM wrapper, as well as the specification and what exactly is and is not a DOM extension.

+4
source share
1 answer

No, Object is listed as part of the Javascript language , and the DOM is an API that is relevant only in the browser environment and is used to access and update the content, structure and style of documents " (W3C) .

However, one of the reasons given in this article, arguing that there is an extension of DOM objects, still refers to the extension of native types such as Object , namely, the probability of collisions.


An object wrap refers to creating a new object that references the original, but provides additional functions through a new shell object.

For example, instead of extending the DOM Element object using the addClass cross-browser addClass as follows:

 var element = document.getElementById('someId'); element.addClass = function (className) { ... }; 

Instead, you can define a wrapper function:

 var ElementWrapper = function (element) { this.element = element; }; 

And add the function to your prototype:

 ElementWrapper.prototype.addClass = function (className) { ... }; 

And wrap the elements as follows:

 var element = document.getElementById('someId'); var wrapped = new ElementWrapper(element); wrapped.addClass('someClass'); 
+8
source

Source: https://habr.com/ru/post/1343859/


All Articles