使用with语句分配初始值

时间:2011-04-27 22:09:29

标签: javascript

以下作品:

var Person = {};
Person.FirstName = '';
Person.LastName = '';
with (Person) {
    FirstName = 'Phillip',
    LastName = 'Senn';
}
log(Person);

但我想删除2-3行。

1 个答案:

答案 0 :(得分:5)

怎么样:

var Person = {FirstName:'Philip', LastName:'Senn'};
log(Person);