The WITH keyword for web effects, with statements intended to provide a namespace-style sketch for progressive object access. That is, in the specified code area, the object is invoked directly through the node name.
With (object) {
Code
}
<title>a Simple page</title>
<script language= "JavaScript" >
<!--
INP1 = 1;
INP2 = 2;
INP3 = 3;
With (Math)
{
Alert ("The largest number entered was" + MAX (INP1, INP2, INP3));
Alert ("The smallest number entered was" + min (inp1, INP2, INP3));
}
-->
</script>
<body>
</body>
Example Two
<script language= "JavaScript" >
<!--
var myNum = 25;
var mye, Mysin, mysqrt;
With (Math) {
Mye = E;
Mysqrt = sqrt (myNum)
Document.writeln (MYSQRT);
Mysin = sin (pi/mynum);
document.write (Mysin);
}
-->
</script>
Using the object parent node to modify the value inside the WITH statement
var root = {
Branch: {
Node:1
}
};
With (Root.branch) {
Root.branch = {
node:0
};
Show 1, Error!
alert (node);
}
Show 0, right!
alert (Root.branch.node);
Note: The node parent node inside the With statement is modified and is not synchronized to the node itself. In other words, there is no guarantee of consistency between internal and external values. This is a potentially highly hidden bug in the project.