Failed to load https://12.img.blabla.st/1280x960/5034079812.jpg: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'localhost:3001' is therefore not allowed access.
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://localhost:3001
Connection: keep-alive
Content-Length: 55063
Date: Mon, 21 Jan 2019 12:03:02 GMT
Server: nginx/1.10.3 (Ubuntu)
console.log( xhr.status + ': ' + xhr.statusText );
console.log( xhr.responseText );
class Promise {
constructor(callback) {
this.state = null;
callback(this.resolve.bind(this), this.reject.bind(this));
return this;
}
resolve() {
this.state = 'resolve';
}
reject() {
this.state = 'reject';
}
then(result, error) {
if (this.state === 'resolve') {
result('it result!!');
return this;
} else if (this.state === 'reject') {
error('it error!!');
return new Error("error message");
}
}
}
const promise = new Promise((resolve, reject) => {
resolve('is resolved');
});
promise.then(
result => {
console.log('result', result);
},
error => {
console.log('error', error);
}
)
.then(
result => {
console.log('result2', result);
},
error => {
console.log('error2', error);
}
);
class Events {
constructor () {
this.listeners = {}
}
get (event) {
return this.listeners[event] || (this.listeners[event] = new Set())
}
addListener (event, listener) {
console.log('addListener start');
this.get(event).add(listener)
}
removeListener (event, listener) {
this.get(event).delete(listener)
}
trigger (event, ...args) {
console.log('trigger start');
this.get(event).forEach(listener => listener(...args))
}
}
class DOMelement {
constructor() {
console.log('construct dom element');
}
}
class WINDOWelement {
constructor() {
console.log('construct window element');
// user click simulation
setTimeout(() => {
console.log('user click to dom element');
this.trigger('click');
}, 3000);
}
}
const events = new Events();
const domElement = new DOMelement();
const windowElement = new WINDOWelement();
domElement.__proto__ = events;
windowElement.__proto__ = events;
domElement.addListener('click', () => { console.log('is clicked') });