var old_element = document.getElementById("btn");
var new_element = old_element.cloneNode(true);
old_element.parentNode.replaceChild(new_element, old_element);
2. Вешаете свой слушатель.const resolve = () => console.log('resolve');
const reject = () => console.log('reject');
const promise2 = () => new Promise((resolve, reject) => {
console.log ('promise2');
const zn = prompt ('digit');
if (zn > 9) {
resolve()
}
else {
reject();
}
});
const myInnerServerTalk = () => new Promise((resolve, reject) => {
console.log (' myInnerServerTalk');
const zn = prompt ('digit');
if (zn > 9) {
resolve()
}
else {
reject();
}
});
myInnerServerTalk().then(resolve).catch(reject);
var x = true;
x = !x;
console.log(x); // false
const fs = require('fs');
fs.readdir('./folder', (err, files) => {
files.forEach(file => {
console.log(file);
});
})
var elements = document.getElementsByClassName('my-class');
Array.prototype.forEach.call(elements, function(element) {
emement.addEventListener('click', function(e) { /* ... */ });
});
var elements = document.getElementsByClassName('my-class');
for (var i = 0; i < emements.length; i++) {
elements[i].addEventListener('click', function(e) { /* ... */ });
}
const elements = document.getElementsByClassName('my-class');
for (let element of elements) {
emement.addEventListener('click', e => { /* ... */ });
}
function getPageIndexes(size, limit) {
var start = 0;
while(true) {
if (start >= size) break;
var end = Math.min(size, start + limit);
console.log(start, end);
start += limit;
}
}
import * as React from 'react';
import styled from 'styled-components';
const Wrapper = styled.label`
position: relative;
display: inline-block;
width: 40px;
height: 24px;
`;
const Input: any = styled.input`
display: none;
`;
const Slider = styled.div`
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .2s;
border-radius: 34px;
&:before {
position: absolute;
content: "";
height: 22px;
width: 22px;
left: 1px;
bottom: 1px;
background-color: white;
transition: .2s;
border-radius: 50%;
}
${Input}:checked + & {
background-color: ${props => props.theme.someColor1};
}
${Input}:focus + & {
box-shadow: 0 0 1px ${props => props.theme.someColor2};
}
${Input}:checked + &:before {
transform: translateX(16px);
}
`;
interface Props = {
name?: string
checked?: boolean
onChange?: Function
innerRef?: Function
className?: string
}
const ToggleSwitch = ({ innerRef, checked, onChange, className, name }: Props) => {
return (
<Wrapper className={className}>
<Input
innerRef={innerRef}
checked={checked}
onChange={onChange}
name={name}
type="checkbox"
/>
<Slider />
</Wrapper>
);
}
componentDidMount() {
this.fetchData();
}
async fetchData() {
try {
const orders = await fetch('orders-path', options).then(response => response.json());
const users = {};
for (let i = 0; i <= orders.length; i++) {
const id = orders[i].user_id;
const user = await fetch('/user/' + id, options).then(response => response.json());
users[id] = user;
}
this.setState({ orders, users });
} catch (e) {
// handle error
}
}
var someVar2 = false;
var someVar3 = false;
var speed = 10;
var baseSpeed = 10;
var someVar2 = false,
someVar3 = false;
speed = 10,
baseSpeed = 10;
var someVar2 = false,
someVar3 = false,
speed = 10,
baseSpeed = 10,