Date and custom objects

# (5) Date
(1) creation date object
new Date (): Thu Apr 02 2020 15:38:04 GMT + 0800 ( China Standard Time)
(2), respectively, to obtain year / month / day
getFullYear () getDate ()
needs Note that, the getMonth () returns the number of groups is zero, 0 represents January
(3) are acquired: minutes: seconds: milliseconds
getHours () getMinutes () the getMilliseconds ()
(. 4) of the days of the week
() obtained by getDay, today is the day of the week
and getMonth () as the return value is zero-based. In digital form can be used to better see the array output date format
(5) milliseconds. 1. 1 experienced 1970
new new a Date () the getTime ();.
(. 6) change date and time
is to get the function to get the date set

# (6) custom objects
new Object () can be defined from the object
, such as Object = new new Object var ();
objec.x =. 1;
object.name = 'Wanghong Yang';
but poor maintenance


Can function Hero (name) {// custom object class js not
this.name = name; // else have to add the phrase undefined
this.kill = function () {
doucument.write (this.name + "the kill Human ");
}

}
Var = new new Hero Hero ( "Yasuo");
hero.kill ();
good definition objects want to add a function of the prototype
var = new new Hero Hero ( "Yasuo");
Hero.prototype.ss = function () {// this object name Hero is not a type name
document.write ( "TOW the I Will the kill" this.name + + "S");
};

 

Guess you like

Origin www.cnblogs.com/whydbk/p/12666645.html