简体   繁体   中英

What does asterisk curly brace *{ mean when defining objects in javascript

For example:

projection = *{
  var projection = d3.geoOrthographic();
  while (true) {
    yield projection.rotate([Date.now() / 200, -20]);
  }
}

I have seen this in this tutorial https://medium.com/@mbostock/a-better-way-to-code-2b1d2876a3a0

but it only runs for me if I use it without the asterisk "*"

projection = {
  var projection = d3.geoOrthographic();
  while (true) {
    yield projection.rotate([Date.now() / 200, -20]);
  }
}

What does the asterisk mean in this context for javascript?

Similar to python, the function * declares a generator function (notice the use of the keyword yield also). ~~This is suggested in ES5~~

Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM