Share via


with 陳述式

更新:2007 年 11 月

為一個陳述式建立預設物件。

 with (object)       statement

引數

  • object
    必要項,新的預設物件。

  • statement
    必要項,當 object 為預設物件時要執行的陳述式,可以是複合陳述式。

備註

with 陳述式通常用來減少您在某些情況下必須撰寫的程式碼量。

範例

請注意到以下範例中重複使用了 Math

var x, y;
x = Math.cos(3 * Math.PI) + Math.sin(Math.LN10);
y = Math.tan(14 * Math.E);

若使用 with 陳述式,您的程式碼會變得比較短且易於判讀:

var x, y;
with (Math){
   x = cos(3 * PI) + sin (LN10);
   y = tan(14 * E);
}

需求

1 版

請參閱

參考

this 陳述式