js學習隨感隨記

function rectangle(w,h)函數

{this

this.width=w;對象

this.height=h;io

}function

這裏是聲明一個函數能夠返回this屬性裏的長和高new

用new能夠建立新的對象而不影響前一個的值

var rect1=new rectangle(2,5);

var rect2=new rectangle(5,7);

這樣rect1和rect2的高度寬度就都分別爲上述()中的值了

相關文章
相關標籤/搜索