我在尝试只在圣诞节那天下“雪”时遇到了一些麻烦。我想出了如何捕获这一天,但我不确定如何让它正确调用 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)
}
}
关于javascript - 在圣诞节调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8631915/