Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of the three points Operator in Javascript

i see rubix code

http://wrapbootstrap.com/preview/WB09498FH (site right up demo click)

it is code in react component

javascript

//react ES6
var InboxItem = React.createClass({
  mixins: [State, Navigation],
  statics: {
    ID: 0,
    resetID: function() {
      InboxItem.ID = 0;
    },
    getID: function() {
      return ++InboxItem.ID;
    }
  },
  handleClick: function(e) {
    e.preventDefault();
    e.stopPropagation();
    this.transitionTo('/app/mailbox/mail');
  },
  render: function() {
    var classes = classNames({
      'inbox-item': true,
      'unread': this.props.unread
    });

    var props = {
      href: '/app/mailbox/mail',
      onClick: this.handleClick,
      ...this.props,
      className: classes
    };

    return (
      <a {...props}>
        <div className='inbox-avatar'>
          <img src={this.props.src} width='40' height='40' className={this.props.imgClass + ' hidden-xs'} />
          <div className='inbox-avatar-name'>
            <div className='fg-darkgrayishblue75'>{this.props.name}</div>
            <div><small><Badge className={this.props.labelClass} style={{marginRight: 5, display: this.props.labelValue ? 'inline':'none'}}>{this.props.labelValue}</Badge><span>{this.props.description}</span></small></div>
          </div>
          <div className='inbox-date hidden-sm hidden-xs fg-darkgray40 text-right'>
            <div style={{position: 'relative', top: 5}}>{this.props.date}</div>
            <div style={{position: 'relative', top: -5}}><small>#{InboxItem.getID()}</small></div>
          </div>
        </div>
      </a>
    );
  }
});

onClick next line code

...this.props

and

return next line code

a {...props}

what is this "..." ?

like image 567
kyunghwanjung Avatar asked Oct 13 '15 01:10

kyunghwanjung


1 Answers

As @zerkms mentioned in the comments; it is the Object Rest/Spread Properties syntax in the ECMAScript 2016 (ES7) Proposal, also mentioned in the React docs.

The code you see

var props = {
  href: '/app/mailbox/mail',
  onClick: this.handleClick,

  ...this.props,

  className: classes
};

gets evaluated to the following, where the props object properties get extended onto the new props object:

var props = {
  href: '/app/mailbox/mail',
  onClick: this.handleClick,

  src: 'https://example.com',
  name: 'myName',
  labelClass: 'myLabelClass',
  labelValue: 'mylabelValue',

  className: classes
};
like image 164
Miguel Mota Avatar answered Nov 15 '22 18:11

Miguel Mota