Javascript 如何在字典中打印,JS中的结构是什么?
我想知道为什么我们需要JS中的这个结构(?),以及我们如何在字典中打印hello worldJavascript 如何在字典中打印,JS中的结构是什么?,javascript,Javascript,我想知道为什么我们需要JS中的这个结构(?),以及我们如何在字典中打印hello world const fun = () => { return { // Q: Is this called dictionary? How can I access to this? matter: panging => { // Q: What's the purpose of having function here? how do we call it?
const fun = () => {
return { // Q: Is this called dictionary? How can I access to this?
matter: panging => { // Q: What's the purpose of having function here? how do we call it?
'the most'; // what's doing here?
console.log('hello world'); //How can I print this?
}
};
};
我们如何在这个函数中打印hello world,
fun
?Javascript中没有字典。你所拥有的是一个具有物质
属性的对象。用fun().matter()调用它fun
将返回一个对象,然后您可以访问(并调用)matter
属性:
constfun=()=>{
return{//Q:这叫字典吗?我怎样才能访问它?
matter:panging=>{//Q:在这里使用函数的目的是什么?我们如何称呼它?
“最大的”;//这里在干什么?
console.log('hello world');//如何打印?
}
};
};
有趣的事代码>Javascript中没有字典。你所拥有的是一个具有物质
属性的对象。用fun().matter()调用它fun
将返回一个对象,然后您可以访问(并调用)matter
属性:
constfun=()=>{
return{//Q:这叫字典吗?我怎样才能访问它?
matter:panging=>{//Q:在这里使用函数的目的是什么?我们如何称呼它?
“最大的”;//这里在干什么?
console.log('hello world');//如何打印?
}
};
};
有趣的事代码>有趣。为什么我们不能像fun()那样访问对象呢?重要的是?当然,你可以这样做-你只需要访问函数本身,而不是调用它。例如setTimeout(fun().matter,1000)代码>将是非常有效和有趣的。为什么我们不能像fun()那样访问对象呢?重要的是?当然,你可以这样做-你只需要访问函数本身,而不是调用它。例如setTimeout(fun().matter,1000)代码>将是完全有效的