Skip to content

Instantly share code, notes, and snippets.

@ethanmick
Last active September 23, 2016 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethanmick/ad7cae12416cda676bcc895ba588cc5b to your computer and use it in GitHub Desktop.
Save ethanmick/ad7cae12416cda676bcc895ba588cc5b to your computer and use it in GitHub Desktop.
'use strict';
class Test {
constructor(opts = {}) {
// NOTE: No Semicolon at the end of this line
const example = JSON.parse(opts.example)
({
id: this.id,
} = example)
}
}
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Test = function Test() {
var _example;
var opts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
_classCallCheck(this, Test);
var example = JSON.parse(opts.example)((_example = example, this.id = _example.id, _example));
};
'use strict';
class Test {
constructor(opts = {}) {
// NOTE: Semicolon at the end of this line
const example = JSON.parse(opts.example);
({
id: this.id,
} = example)
}
}
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Test = function Test() {
var opts = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
_classCallCheck(this, Test);
var example = JSON.parse(opts.example);
this.id = example.id;
};
@ethanmick
Copy link
Author

Using ES6 destructuring to assign values to this, you need to be careful how the parenthesis are interpreted!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment