论坛首页 Web前端技术论坛

javascript with用法

浏览 21357 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (3) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-07-31  
with (object)
   statements
参数
object
新的默认对象。
statements
一个或多个语句,object 是该语句的默认对象。
说明
with 语句通常用来缩短特定情形下必须写的代码量。在下面的例子中,请注意 Math 的重复使用:

x = Math.cos(3 * Math.PI) + Math.sin(Math.LN10)
y = Math.tan(14 * Math.E)
当使用 with 语句时,代码变得更短且更易读:

with (Math){
   x = cos(3 * PI) + sin (LN10) 
   y = tan(14 * E)
}
   发表时间:2008-07-31  
with会把参数对象加入到{}代码块执行环境(execution context)里面的作用域链(scope chain)的首部,会修改索引对象的顺序
http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Statements:with
0 请登录后投票
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics