給定函數/類型聲明是這樣的:通過調用具有參數列表的構造函數來實例化對象使用apply?
function Person(name, ... other args ...){
this.name
... other init code ...
}
我想能夠調用的Person構造函數的參數數組被應用到它。我可以這樣做:
Person.apply(this, args)
除了這不會實例化一個人,它只是將其稱爲一個函數。有什麼辦法,你把它用這種方式,但在「新」的情況下,即表現得像:
new Person(...)
Dup的:http://stackoverflow.com/questions/813383/how-can-i-construct-an-object-using-an-array-of -values-for-parameters-rather-tha – 2009-09-03 01:02:14