Say I have a JavaScript library to create a DOM fragment, as shown below.
<main>
<h1>A heading</h1>
<p>A paragraph</p>
</main>
where the library domlibhas methods for any type of element, and the function generating the above fragment may look like this:
function(domlib){
return domlib.main(
domlib.h1('A heading'),
domlib.p('A paragraph')
);
}
Inside this function, I would like to call methods domlibas follows:
main(
h1('A heading'),
p('A paragraph')
)
To achieve this, I could place all the methods domlibin a global area, but I would prefer not to pollute the global area. For me, this is apparently the case when the statement withwould be the perfect solution:
function(domlib){
with(domlib){
return main(
h1('A heading'),
p('A paragraph')
);
}
}
Despite the fact that the operator iswith supported, it is practically not recommended and it will display an error in strict mode .
, , domlib , , ( domlib ) .
, , , , with?