Creating/populating Javascript custom object
Posted
by Ek0nomik
on Stack Overflow
See other posts from Stack Overflow
or by Ek0nomik
Published on 2010-05-10T19:03:10Z
Indexed on
2010/05/10
19:44 UTC
Read the original article
Hit count: 224
JavaScript
|object
I've created an ashx page which is going to serve me an XML document full of basic user information. I'm not sure which is the best way to go about creating and populating my custom javascript object. I've seen them created in two ways:
function User() {
this.Id;
this.FirstName;
this.LastName;
this.Title;
}
and
var User2 = {
Id: null,
FirstName: null,
LastName: null,
Title: null
}
I could populate each of these by doing something like:
//first object
User.Id = 1
//second object
User2.FirstName = 'John'
Is one method of creating the object better than the other?
© Stack Overflow or respective owner