arrow function in callback
by Artem
JavaScript
'use strict';
function doRequest(url, cb) {
const data = {};
data.tags = ['one', 'two', 'three'];
setTimeout(() => {
cb(data);
}, 2000);
}
function TestComponent(target, url) {
this.target = target;
this.url = url;
}
TestComponent.prototype.render = function() {
doRequest(this.url, data => {
console.log(data, this);
});
};
const c = new TestComponent('div', 'hello/');
c.render();