我在尝试仅在圣诞节那天将其设置为“雪”时遇到了一些麻烦。我想出了如何度过美好的一天,但不确定如何正确调用SnowStorm()。
var christmas = {
month: 11,
date: 25
}
function isItChristmas() {
var now = new Date();
var isChristmas = (now.getMonth() == christmas.month && now.getDate() == christmas.date);
if (isChristmas)
return ;
else
return ;
}
var snowStorm = null;
function SnowStorm() {
(snowstorm code)
}
snowStorm = new SnowStorm();
最佳答案
如果您打算创建一个函数(不是类),则为以下版本:
var christmas = {
month: 12,
date: 25
}
function isItChristmas() {
var now = new Date();
return (now.getMonth() == christmas.month && now.getDate() == christmas.date);
}
if (isItChristmas()){
SnowStorm();
}else{
//not a christmas
}
function SnowStorm() {
(snowstorm code)
}
如果您打算上课,这里是一个:var christmas = {
month: 12,
date: 25
}
function isItChristmas() {
var now = new Date();
return (now.getMonth() == christmas.month && now.getDate() == christmas.date);
}
var storm = new SnowStorm();
if (isItChristmas()){
storm.Snow();
}else{
//not a christmas
}
function SnowStorm() {
this.Snow = function(){
(snowstorm code)
}
}