Curly braces inside JavaScript arguments for functions

后端 未结 4 984
再見小時候
再見小時候 2020-12-12 19:16

What do the curly braces surrounding JavaScript arguments for functions do?

var port = chrome.extension.connect({name: "testing"});
port.postMessage         


        
4条回答
  •  生来不讨喜
    2020-12-12 20:00

    Curly braces in javascript are used as shorthand to create objects. For example:

    // Create an object with a key "name" initialized to the value "testing"
    var test = { name : "testing" };
    alert(test.name); // alerts "testing"
    

    Check out Douglas Crockford's JavaScript Survey for more detail.

提交回复
热议问题