如何构造已定义对象的新实例?
我有与此类似的代码,但this.User = new User();
它不起作用。
(function () {
SomeApp = {
User: {
FirstName: '',
LastName: ''
},
Users: [],
init: function () {
this.User.FirstName = 'Joe';
this.User.LastName = 'Blogs';
//add user to list
var copiedUser = {};
$.extend(copiedUser, this.User);
this.Users.push(copiedUser);
//create new user
this.User = new User();
this.User.FirstName = 'Jane';
//add user to list
var copiedUser = {};
$.extend(copiedUser, this.User);
this.Users.push(copiedUser);
}
}
SomeApp.init();
})();