async function loop() {
for (let i = 0; i < 3; i++) {
await click();
}
}
function click() {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log('Click async')
return resolve();
}, 2000)
});
}
var timer = 0;
const callbacks = [];
for (let i = 0; i <= 10; i++) {
timer += 100;
callbacks.push(promisedTimeout(() => {
console.log(i);
return i;
}, timer)) ;
}
function promisedTimeout(callback, timer) {
return new Promise((resolve, reject) => {
setTimeout(() => {
return resolve(callback());
}, timer)
});
}
function end() {
Promise.all(callbacks)
.then(res => console.log("THE END"))
}
end()
class Foo {
constructor() {
this._field = '';
}
set field(value) {
this._field = value+='Foo';
}
get field() {
return this._field;
}
}
class MyFoo extends Foo {
set field(value) {
super.field = value;
this._field += 'MyFoo';
}
}
click(e, index){
console.log(e.altKey);
let unit = this.state.array;
}
render() {
let array = this.state.array;
let unit = array.map((item, index) => {
return (
<a key={index}
style={{display:"block"}}
onClick={(e)=>this.click(e, index)}
>Hello, {item}</a>
)
});
module.exports = async function имя1(params) {
try {
const response = await request(params);
let charset = [];
charset.name = response.data;
const charsetResult = await someFunc(charset);
if (charsetResult.value === undefined) {
charsetResult.value = 'PR10';
} else {
charsetResult.guild = charset.guild.name;
}
return charsetResult;
} catch (error) {
console.log(error);
};
}
function userFadeout2(el, delay, opacity) {
return new Promise((resolve, reject) => {
delay = typeof delay !== 'undefined' ? delay : 50;
if (el.style.opacity == "") {
el.style.opacity = 1;
opacity = el.style.opacity;
}
else if (typeof opacity !== 'undefined') {
el.style.opacity = opacity;
}
else {
opacity = el.style.opacity;
}
if (opacity == 0) {
el.style.display = 'none';
console.log('конец');
return resolve(true)
}
else {
setTimeout(function () {
opacity -= 0.1;
console.log(opacity);
return resolve(userFadeout2(el, delay, opacity.toFixed(1)));
}, delay);
}
})
}