1

Here's some sample code from ReactKungfu:

var CommentBox = React.createClass({
  render: function() {
    return (
      <div className="commentBox">
        Hello, world! I am a CommentBox.
      </div>
    );
  }
});

What does the : in render: function() signify? I haven't seen this explained in vanilla JS tutorials I have done, although I believe it signifies "[something] in [this other list/range] in Java

GPP
  • 2,157
  • 3
  • 18
  • 26
  • 3
    It's just a normal object. The opening curly brace is at the end of the previous line. – JJJ Nov 18 '18 at 21:41
  • @JJJ thanks! I kind of missed the JSON structure when I was staring at this for 15 mins – GPP Nov 18 '18 at 22:41
  • 2
    That happens, although [it's not JSON](https://stackoverflow.com/a/2904181). – JJJ Nov 18 '18 at 22:44
  • @JJJ fair point -- so reading from your link, is it accurate to say this `{render: ... }` is a JavaScript object literal? – GPP Nov 18 '18 at 23:11

1 Answers1

2

The curly brackets you put around the data passed into the function represent a JS object. render is simply a member variable of that object, so the : is to define that variable as the function after it.

It's basically equivalent to let render = function() { ... } outside of an object.

Julxzs
  • 737
  • 1
  • 7
  • 21