(function Slider() {
function Slider(slides, startIndex = 0) {
this.slides = slides
this.currentSlideIndex = startIndex
}
Slider.prototype.getCurrentSlide = function() {
return this.slides[this.currentSlideIndex]
}
return Slider
})()
const slider = new Slider(document.querySelectorAll(".slider-item"))
slider.getCurrentSlide()
for(var i = 0; i < diaryIcons.length; i++){
return images('./' + diaryIcons[i].name + ".png")
}
class EventEmitter {
constructor() {
const delegate = document.createDocumentFragment();
[
'addEventListener',
'dispatchEvent',
'removeEventListener'
].forEach(f =>
this[f] = (...xs) => delegate[f](...xs)
)
}
public addEventListener(event: string, callback: Function) {}
public removeEventListener(event: string, callback: Function) {}
public dispatchEvent(event: Event) {}
}
export class CustomLocalStorage extends EventEmitter {
private successSetEvent: Event
private errorSetEvent: Event
constructor(public prefix: string = 'local') {
super()
this.successSetEvent = new CustomEvent(`set:success`)
this.errorSetEvent = new CustomEvent(`set:error`)
}
public setItem(key: string, value: any) {
try {
localStorage.setItem(`${this.prefix}-${key}`, JSON.stringify(value))
this.dispatchEvent(this.successSetEvent)
} catch (error) {
this.dispatchEvent(this.errorSetEvent)
}
}
public getItem(key: string) {
return JSON.parse(localStorage.getItem(`${this.prefix}-${key}`))
}
}
const lStorage = new CustomLocalStorage('lStorage')
lStorage.addEventListener('set:success', function() {
alert('success')
})
lStorage.setItem('any', true)
setTimeout(function() {
lStorage.setItem('foo', {
a: 1,
b: 2
})
}, 2000)
<svg xmlns="http://www.w3.org/2000/svg"><use href="#СсылкаНаСвгЭлемент"/><svg>
const speedControlArea = document.querySelector('[scroll-speed-control]')
const maxSpeedOffset = 300
let controlAreaOffset = 0
let scrollSpeedTimeout
document.body.addEventListener('scroll', e => {
controlAreaOffset = speedControlArea.scrollTop
clearTimeout(scrollSpeedTimeout)
scrollSpeedTimeout = setTimeout(() => {
if (controlAreaOffset - speedControlArea.scrollTop > maxSpeedOffset ) {
alert(1)
} else {
alert(2)
}
}, 300)
})
<a href="https://мойсайт.ru/profile/{{ review.rating_user_name}}"><span class="rwp-u-review__username" v-text="review.rating_user_name"></span></a>
imgs.map(i => {
let img = $('<img class="grid-item din"/>').attr('src', i)
ins.push(img)
return new Promise(resolve => {
img.on('load', e => resolve())
})
})
Promise.all(imgs).then(function() {
//do
})
var arr = [1, 2, 3]
var copyArr = new Array(...arr)
copyArr.splice(0, 2)
console.log(arr) // -> [1, 2, 3]
var cloneArr = function(arr) {
return Array.apply(null, arr)
}
var arr = [1, 2, 3, 4, 5]
var clonedArr = cloneArr(arr)
clonedArr.splice(0, 4)
console.log(arr) // -> [1, 2, 3, 4, 5]
console.log(clonedArr) // -> [5]
$.post(location.href, {}, function(data){
charts = data;
return charts;
}, 'json');
console.log(charts);
ответ еще может не прийти. И получаете undefined.$.post(location.href, {}, function(data){
console.log(data)
doSomething(data)
}, 'json');
Аналогичный код из сайта mkad.mapcraft.ru работает без ошибок. Сторонные библиотеки не подключены.