i have the following code which creates a new object:
function Person(firstname, lastname, birth) {
this.name = firstname + " " + lastname;
this.bdate = {
year: birth.getFullYear(),
day: birth.getDate(),
month: "January,Febuary,March,April,May,June,July,August,September,October,November,December".split(",")[birth.getMonth() - 1],
monthnumber: birth.getMonth(),
}
this.age = new Date().getFullYear() - birth.getFullYear();
}
var foo = new Person("Jon", "Doe", new Date(1996, 12, 5));
console.log(foo);
when i do the following code:
var foo = new Person("Jon", "Doe", new Date(1996, 12, 5));
it does exactly what it should do: create a new Person object.
BUT
this is what i get when do foo in console:
foo
Object { name: "Jon Doe", bdate: Object, age: 20 }
when i click on bdate object i get:
month: undefined
how to fix? PLUS year is 1997 instead of 1996
EDIT:no it's not duplicate of getutcmonth, that problem is treating 12 AS 0, mine returns undefined for month
ANOTHER EDIT:huh, i guess it acually is duplicate :P still, can you help me?