嗨,我想知道为什么我在不使用console.log(jakubpresentation)
的情况下设置以下变量时仍能看到它的原因?
var jakubpresentations = jakub.presentation("formal", " morning ");
var jakub = {
name: "jakub",
surname: "klos",
age: 18,
profession: "designer",
presentation: function(style, timeOfDay) {
if (style === "formal") {
console.log("good " + timeOfDay + this.name + " Welcome in DesignUX Company")
} else if (style === "nonformal") {
console.log("Hi" + this.name + "Welcome in DesignUX Company");
}
}
}
var justyna = {
name: "justyna",
surname: "rybicka",
age: 28
}
var jakubpresentations = jakub.presentation("formal", " morning ");
答案 0 :(得分:1)
您将jakubpresentations
的值设置为从函数jakub.presentation
返回的值。
var jakubpresentations = jakub.presentation("formal", " morning ");
当您将变量设置为等于函数调用时,该函数将运行。整个功能将执行。 console.log
语句在您运行的函数中。
presentation: function(style, timeOfDay) {
if (style === "formal") {
console.log("good " + timeOfDay + this.name + " Welcome in DesignUX Company")
} else if (style === "nonformal") {
console.log("Hi" + this.name + "Welcome in DesignUX Company");
}
}
您可以通过使用函数来创建变量来运行它。您不必自己给它一整行。