• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

js中with的和case的用法

发布: 2007-6-30 18:56 | 作者: admin | 来源: | 查看: 92次 | 进入软件测试论坛讨论

领测软件测试网 switch Statement<br>
Enables the execution of one or more statements when a specified expression@#s value matches a label.<br>
<br>
switch (expression) {<br>
&nbsp;&nbsp;&nbsp;case label :<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;statementlist<br>
&nbsp;&nbsp;&nbsp;case label :<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;statementlist<br>
&nbsp;&nbsp;&nbsp;...<br>
&nbsp;&nbsp;&nbsp;default :<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;statementlist<br>
} <br>
<br>
Arguments<br>
expression<br>
<br>
The expression to be evaluated.<br>
<br>
label<br>
<br>
An identifier to be matched against expression. If label === expression, execution starts with the statementlist immediately after the colon, and continues until it encounters either a break statement, which is optional, or the end of the switch statement.<br>
<br>
statementlist<br>
<br>
One or more statements to be executed.<br>
<br>
Remarks<br>
Use the default clause to provide a statement to be executed if none of the label values matches expression. It can appear anywhere within the switch code block. <br>
<br>
Zero or more label blocks may be specified. If no label matches the value of expression, and a default case is not supplied, no statements are executed.<br>
<br>
Execution flows through a switch statement as follows: <br>
<br>
Evaluate expression and look at label in order until a match is found. <br>
If a label value equals expression, execute its accompanying statementlist. <br>
Continue execution until a break statement is encountered, or the switch statement ends. This means that multiple label blocks are executed if a break statement is not used. <br>
If no label equals expression, go to the default case. If there is no default case, go to last step. <br>
Continue execution at the statement following the end of the switch code block. <br>
Example<br>
The following example tests an object for its type. <br>
<br>
function MyObject() {<br>
...}<br>
<br>
switch (object.constructor){<br>
&nbsp;&nbsp;&nbsp;case Date:<br>
&nbsp;&nbsp;&nbsp;...<br>
&nbsp;&nbsp;&nbsp;case Number:<br>
&nbsp;&nbsp;&nbsp;...<br>
&nbsp;&nbsp;&nbsp;case String:<br>
&nbsp;&nbsp;&nbsp;...<br>
&nbsp;&nbsp;&nbsp;case MyObject:<br>
&nbsp;&nbsp;&nbsp;...<br>
&nbsp;&nbsp;&nbsp;default: <br>
&nbsp;&nbsp;&nbsp;...<br>
}<br>
Requirements<br>
Version 3<br>
<br>
with Statement<br>
Establishes the default object for a statement. <br>
<br>
with (object)<br>
&nbsp;&nbsp;&nbsp;statements <br>
<br>
Arguments<br>
object<br>
<br>
The new default object.<br>
<br>
statements<br>
<br>
One or more statements for which object is the default object.<br>
<br>
Remarks<br>
The with statement is commonly used to shorten the amount of code that you have to write in certain situations. In the example that follows, notice the repeated use of Math. <br>
<br>
x = Math.cos(3 * Math.PI) + Math.sin(Math.LN10) <br>
y = Math.tan(14 * Math.E)<br>
When you use the with statement, your code becomes shorter and easier to read: <br>
<br>
with (Math){<br>
&nbsp;&nbsp;&nbsp;x = cos(3 * PI) + sin (LN10)&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;y = tan(14 * E)<br>
}<br>
Requirements<br>
Version 1

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网