Unfamiliar use of square brackets in calling a function

前端 未结 5 2164
滥情空心
滥情空心 2021-02-19 23:41

In the middle of this page, I find the code below.

var plus = function(x,y){ return x + y };
var minus = function(x,y){ return x - y };

var operations = {
  \'+         


        
5条回答
  •  鱼传尺愫
    2021-02-20 00:06

    here operations is an object where the symbols + and - refers to two functions.

    operations[operation] will return a reference to function plus where value of operation is + and then the following () will invoke the function

提交回复
热议问题