title: Javascript apply - example in Mixins in React
body: <p>Here is a piece of code from React documentation.</p>
  
  <p>I am trying to parse what is going on with the when we call setInterval in the component :</p>
  
  <pre><code>var SetIntervalMixin = {
    componentWillMount: function() {
      this.intervals = [];
    },
    setInterval: function() {
      this.intervals.push(setInterval.apply(null, arguments));
    },
    componentWillUnmount: function() {
      this.intervals.map(clearInterval);
    }
  };
  
  var TickTock = React.createClass({
    mixins: [SetIntervalMixin], // Use the mixin
    getInitialState: function() {
      return {seconds: 0};
    },
    componentDidMount: function() {
      this.setInterval(this.tick, 1000); // Call a method on the mixin
    },
    tick: function() {
      this.setState({seconds: this.state.seconds + 1});
    },
    render: function() {
      return (
        &lt;p&gt;
          React has been running for {this.state.seconds} seconds.
        &lt;/p&gt;
      );
    }
  });
  
  React.render(
    &lt;TickTock /&gt;,
    document.getElementById('example')
  );
  </code></pre>
  
  <ul>
  <li>Am I correct to say : when we do</li>
  </ul>
  
  <blockquote>
    <p>this.setInterval(this.tick, 1000); // Call a method on the mixin</p>
  </blockquote>
  
  <p>We call the mixin <code>setInterval</code>, which despite having no arguments has a keyword <a href="https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Fonctions/arguments" rel="nofollow">arguments</a> we can use in the body, where we call <a href="https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Function/apply" rel="nofollow">apply</a> on another <a href="http://www.w3schools.com/jsref/met_win_setinterval.asp" rel="nofollow">setInterval</a> from the <code>Window</code> namespace, giving <code>null</code> as 1st argument, as it is a pure function, and as argument the closure (function + its state closed over) we want to be seen executed, alongside the refresh rate ?</p>
  
  <ul>
  <li>Bonus question : is there any benefit for not having explicit higher order arguments and say Window.setInterval(callback, interval) ? </li>
  </ul>