with

Summary

Specifies a default object for a statement.

Syntax

with (object) {
    statement1;
    statement2;
    statement3;
}

Parameters

object
The name of the object to be used as the default. This can be any valid identifier.
statementN
The statements to be executed.

Description

with is deprecated in JS++.

with creates a default object for use with the specified statements. Expressions within the statement block will be evaluated by first assuming names refer to properties of the default object. If the default object does not possess that property, the name will be evaluated as usual.

Because of the possibility of human confusion and the creation of bugs which are difficult to detect and correct, it is not recommended to use with with names that are used both for properties of the default object and for local or global variables.

Examples

Example showing scope
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import System;
import Externals.DOM;
 
var planet = {
    name: "Vulcan",
    mass: 5.0,
    radius: 2.0,
    givename: function() {
        Console.log("Name of planet is" + this.name);
    }
};
double mass = 10.0;
double luminosity = 70.0;
 
with (planet) {
    alert(mass);       // Returns planet.mass = 5.0
    alert(luminosity); // Returns 70.0
    givename;          // Returns "Name of planet is Vulcan"
}
 
alert(mass); // Outside of 'with' statement, so returns 10.0

See Also

Share

HTML | BBCode | Direct Link