Javascript: Passing variable into Promise
<p>I am working on an open source EmberJS project that is making an Ajax request for information and then needs to resolve based on a dynamic subpart of the response.  </p>

<pre><code>  return new Promise((resolve, reject) =&gt; {
    const { resourceName, identificationAttributeName } = this.getProperties('resourceName', 'identificationAttributeName');
    const data         = {};
    data[resourceName] = { password };
    data[resourceName][identificationAttributeName] = identification;

    return this.makeRequest(data).then(
      (response) =&gt; run(null, resolve, response),
      (xhr) =&gt; run(null, reject, xhr.responseJSON || xhr.responseText)
    );
  });
</code></pre>

<p>....</p>

<pre><code>makeRequest(data, options) {
  const serverTokenEndpoint = this.get('serverTokenEndpoint');
  const requestOptions = $.extend({}, {
    url:      serverTokenEndpoint,
    type:     'POST',
    dataType: 'json',
    data,
    beforeSend(xhr, settings) {
      xhr.setRequestHeader('Accept', settings.accepts.json);
    }
  }, options || {});

  return $.ajax(requestOptions);
}
</code></pre>

<p>In the end, I need the success response to run something like </p>

<pre><code>(response) =&gt; run(null, resolve, response[resourceName])
</code></pre>

<p>but inside the response function, I have no access to the resourceName.  How would I send this in?</p>

<p>here is the transpiled code:</p>

<pre><code>  var _this = this;

  return new Promise(function (resolve, reject) {
    var _getProperties2 = _this.getProperties('resourceName', 'identificationAttributeName');

    var resourceName = _getProperties2.resourceName;
    var identificationAttributeName = _getProperties2.identificationAttributeName;

    var data = {};
    data[resourceName] = { password: password };
    data[resourceName][identificationAttributeName] = identification;

    return _this.makeRequest(data).then(function (response) {
      run(null, resolve, response);
    }, function (xhr) {
      return run(null, reject, xhr.responseJSON || xhr.responseText);
    });
</code></pre>