<code lang="html">
<!DOCTYPE html>
<html>
<body>
<h2>My Hell looper</h2>
<button type="button" id="stopBtn">STOP THIS!!!</button>
<p id="counter"></p>
<p id="demo"></p>
<script>
let counter = 0, keepLooping = true;
const htmlCounter = document.getElementById("counter");
const step = () => {
console.log(counter++);
htmlCounter.innerHTML = counter;
}
const loop = () => {
if (!keepLooping) {
htmlCounter.innerHTML = `stopped at ${counter} step by click!`;
return;
}
step();
setTimeout(loop, 1000);
}
const btn = document.getElementById("stopBtn");
btn.onclick = function(){
keepLooping = false;
}
/*START HELL*/
loop();
</script>
</body>
</html>
</code>
const gmExample = {
"south": 43.106491921792255,
"west": 76.71745650634767,
"north": 43.4065384633472,
"east": 77.13974349365236
};
const dgExample= {
"northEast": [
76.92894332280319,
43.25695003829279
],
"southWest": [
76.92825667730312,
43.256449960663694
]
};
const gm = {
"south": dgExample.southWest[1],
"west": dgExample.southWest[0],
"north": dgExample.northEast[1],
"east": dgExample.northEast[0]
};
const dg = {
"northEast": [
gmExample.east,
gmExample.north
],
"southWest": [
gmExample.west,
gmExample.south
]
};
class CompatibleBounds {
northEast = [0, 0];
southWest = [0, 0];
constructor(bounds) {
Object.assign(this, bounds);
}
static new(bounds) {
return new this(bounds);
}
get south(){ return this.southWest[1] }
get west(){ return this.southWest[0] }
get north(){ return this.northEast[1] }
get east(){ return this.northEast[0] }
set south(value){ this.southWest[1] = value }
set west(value){ this.southWest[0] = value }
set north(value){ this.northEast[1] = value }
set east(value){ this.northEast[0] = value }
}
const compatibleBounds = CompatibleBounds.new({
"south": 43.106491921792255,
"west": 76.71745650634767,
"north": 43.4065384633472,
"east": 77.13974349365236
});
// или
const compatibleBounds = CompatibleBounds.new({
"northEast": [
76.92894332280319,
43.25695003829279
],
"southWest": [
76.92825667730312,
43.256449960663694
]
});
// на выходе универсальный динамический объект:
compatibleBounds.southWest = [1, 2];
console.log(compatibleBounds.south); // 2
compatibleBounds.south = 3
console.log(compatibleBounds.southWest); // [1, 3]