With...End With: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
m (Ghenne moved page With...end with to With...End With)
No edit summary
 
(6 intermediate revisions by 3 users not shown)
Line 9: Line 9:
== Example ==
== Example ==


<pre>
<tabber>
JavaScript=
<syntaxhighlight lang="JavaScript">
/* With statement allows accessing properties on a specified object */
 
var theURL, theTitle;
with (document) {
  theURL = URL;
  title = "New Title";
  theTitle = title;
  NSB.Print(URL);
  NSB.Print(title);
}
 
/* a better way to perform With */
 
(function($){
    theURL = $.URL;
    $.title = "New Title";
    theTitle = $.title;
    NSB.Print($.URL);
    NSB.Print($.title);
  }(document)
);</syntaxhighlight>
|-|
BASIC=
<syntaxhighlight lang="vb.net">
Rem With sample
Rem With sample
'With statement allows accessing properties on a specified object
Dim theURL, theTitle
With document
With document
  theURL = .URL
  .title = "New Title"
  theTitle = .title
   Print .URL
   Print .URL
   Print .title
   Print .title
  Print .doctype
End With</syntaxhighlight>
End With
</tabber>
</pre>


== Output ==
== Output ==
Line 22: Line 53:
<pre>
<pre>
File:///C:Browse.htm
File:///C:Browse.htm
Test
New Title
[objectDocumentType]
</pre>
</pre>
== Related Items ==
[[class|Class]]


[[Category:Language Reference]]
[[Category:Language Reference]]


[[Category:Statements - Flow of control]]
[[Category:Statements - Flow of control]]

Latest revision as of 23:40, 24 July 2019

With object

[statements]

End With

Description

With allows you to do a series of operations on an object without having to name the object each time.

Example

/* With statement allows accessing properties on a specified object */

var theURL, theTitle;
with (document) {
  theURL = URL;
  title = "New Title";
  theTitle = title;
  NSB.Print(URL);
  NSB.Print(title);
}

/* a better way to perform With */

(function($){
    theURL = $.URL;
    $.title = "New Title";
    theTitle = $.title;
    NSB.Print($.URL);
    NSB.Print($.title);
  }(document)
);

Rem With sample
'With statement allows accessing properties on a specified object

Dim theURL, theTitle
With document
  theURL = .URL
  .title = "New Title"
  theTitle = .title
  Print .URL
  Print .title
End With

Output

File:///C:Browse.htm
New Title