首页 > 请问这样的return是什么写法

请问这样的return是什么写法

我印象中记得看过某断代码,他的返回大概是

function a{
。。。。
    return{
        ...
        ...
        ...
        ...
    }
}

具体怎么写忘记了,返回中有 花括号 是什么意思呢,能不能写个例子


有花括号代码里面是一个对象,如

function a (){
    return {
        b: "hello,world"
    }
}

然后

> a().b
"hello,world"

这里的b也可以是一个方法

function a (){
return {
    b: function(){
        console.log("hello,world")
}}}

{} 定义对象字面量


返回一个对象

function test(){
    return {
         name:"test",
         age:23
    }
}

var obj = test();
alert(obj.name);   //test
【热门文章】
【热门文章】