Curly braces inside JavaScript arguments for functions

后端 未结 4 986
再見小時候
再見小時候 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:12

    var x = {title: 'the title'};
    

    defines an object literal that has properties on it. you can do

    x.title 
    

    which will evaluate to 'the title;

    this is a common technique for passing configurations to methods, which is what is going on here.

提交回复
热议问题