prev.addEventListener('click', ()=>{
// правильно current
if (curentMonth == 0) curentYear -= 1
curentMonth = (12 + curentMonth - 1) % 12
createCalendar(calendar, curentYear, curentMonth);
months.innerHTML = monthsName[curentMonth];
years.innerHTML = curentYear;
})
const validTelegramNickname = /^[A-Za-z\d_]{5,32}$/;
function initWebGL(canvas){
var ctx = null;
for (name of ["webgl", "experimental-webgl"]){
try {
ctx = canvas.getContext(name);
} catch(error) {
console.log(name + ' not supported');
}
if (ctx) break;
}
return ctx;
}
let canvas = document.createElement('canvas');
const webGL = initWebGL(canvas);
if (webGL) // supported
else // not supported
function calculateResults(users,results){
let map = new Map();
let total = 0;
for (let result of results){
let exist = map.get(result.id);
if (exist) exist.counts += result.counts;
else map.set(result.id, result.counts);
total += result.counts;
}
for (let user of users){
user.result = (map.get(user.id) || 0) * 100 / total;
}
return users;
}
function getValue(objectValues, valueString, defaultV = '') {
let current = objectValues;
for (let key of valueString.split('.')){
if (Object.prototype.toString.call(current) === '[object Object]' && key in current) {
current = current[key]
} else return defaultV
}
return current
}
const getValue = (objectValues, valueString = '', defaultV = '') => valueString.split('.').reduce((value, key) => value.hasOwnProperty(key) ? value[key] : defaultV, objectValues);
<html>
<head>
<script>
function main(){
a = b;
}
window.addEventListener('load', function(){
try {
main()
} catch (e){
proceedException(e)
}
})
</script>
<script src="file.js">
</script>
</head>
<body>
<div id="error">
</div>
</body>
</html>
function parseStackTrace(stacktrace){
let [_, functionName, fileName, row, __, column] = stacktrace.match(/at\s([^\s]+)\s\((.+?):(\d+)(:(\d+))?\)/)
return [functionName, fileName, row, column]
}
function proceedException(exception){
let [fn, file, row, column] = parseStackTrace(exception.stack),
node = document.createElement('p');
node.innerText = `Ошибка в файле: ${file}, функция <${fn}> на строке ${row}${column ? '(' + column + ' символ)' : ''} ${exception}`;
document.querySelector('#error').appendChild(node);
}
function helper(){
let c = 1, a = b;
}
function onload(){
helper();
}
window.addEventListener('load', function(){
try {
onload()
} catch (e){
proceedException(e)
}
})
const box = document.querySelectorAll('.box');
const box = [...document.querySelectorAll('.box') ];
Application.whenUserAdd( item => box.push(item))
document.querySelector('nav').addEventListener('click', event => {
let box = document.querySelectorAll('.box');
var AsyncDataLoader = function(options){
var data, error, promise = new Promise( function(resolve, reject){
axios.request(options).then(function (response) {
resolve(data = response.data);
}).catch(function (err) {
reject(error = err);
})
});
this.getData = function(){
return error ? Promise.reject(error) : data ? Promise.resolve(data) : promise;
}
}
let dataBox = new AsyncDataLoader({
method: 'GET',
url: '*************************',
params: {page: '1'},
headers: {
accept: 'application/json',
Authorization: 'Token **************',
'X-CSRFToken': '*************************************'
}
});
dataBox.getData().then( data => doSomeWith(data))
// other code
// ..
// other code
dataBox.getData().then( data => doSomeWith(data))
var data = []
function change(node){
let [ row, col ] = node.dataset.id.substring(1,).split('c').map(v => --v);
if (!data[row]) data[row] = [];
if (node.value) data[row][col] = +node.value;
}
document.querySelectorAll('input').forEach( node => {
change(node);
node.addEventListener('change', e => change(e.target));
});
// чтобы меньше бегать в циклах
let foldersMap = new Map();
for (let folder of folders_h)
foldersMap.set(folder.id, { children: folder.children })
for (let folder of folders){
let item = foldersMap.get(folder.id)
if (item) item.name = folder.name
else foldersMap.set(folder.id, { name: folder.name });
}
function helper(id){
let folder = foldersMap.get(id);
return !folder.children ? { id, name: folder.name } : { id, name: folder.name, children: folder.children.map( child => helper(child) ) }
}
let collection = folders_h.find( folder => folder.id === folders_root_id).children.map(child => helper(child))