continuation icon indicating copy to clipboard operation
continuation copied to clipboard

`this` get lost in try block

Open shankerwangmiao opened this issue 10 years ago • 0 comments

 a={}
  a.b=(cb)->
    console.log this
    try
      console.log this
      this.b cont()
    catch err
      console.error err
  a.b()

the output code is

(function () {
  var a;
  a = {};
  a.b = function (cb) {
    var err;
    console.log(this);
    (function (_$cont) {
      try {
        console.log(this);
        return this.b(function (arguments) {
          try {
            _$cont();
          } catch (_$err) {
            _$cont(_$err);
          }
        }.bind(this, arguments));
      } catch (_$err) {
        _$cont(_$err);
      }
    }(function (_error) {
      if (_error !== undefined) {
        err = _error;
        return console.error(err);
      }
    }));
  };
  a.b();
}.call(this));
/* Generated by Continuation.js v0.1.7 */

Apparently, this get lost in the structure


(function (_$cont) {
  //...
})(function (_error) {
})

shankerwangmiao avatar May 12 '15 17:05 shankerwangmiao