What do you call this JavaScript syntax, so I can research it?

前端 未结 7 586
一向
一向 2020-12-18 00:57

1) In the following code, what is the reasoning behind making gameOfLive a variable and not just function gameOfLife()?

2) What is go

相关标签:
7条回答
  • 2020-12-18 01:33

    sure: to explain the syntax:

    functions are first class objects in javascript, so you can put a function into a variable. thus the main part of this code is in fact a function definition stored in var gameOfLife, which could later be used by calling:

    gameOfLife()
    

    gol is an object (hash), and "init" is another example of the above syntax, except put directly into the "init" key in the "gol" hash. so that function in turn could be called by:

    gol["init"](w,h)
    
    0 讨论(0)
提交回复
热议问题