var myaudio = $("#myaudio")[0];$("#myblock a").mouseenter(function(){myaudio.play();});
искомых элементов еще нет на странице, нужно так:$(function() {
var myaudio = $("#myaudio")[0];
$("#myblock a").mouseenter(function(){myaudio.play();});
});
function findParamPath(obj, prop) {
if(obj.hasOwnProperty(prop)) return prop;
var props = Object.getOwnPropertyNames(obj);
for(var i = props.length; i--; ) {
if(typeof obj[props[i]] !== 'object') continue;
var path = findParamPath(obj[props[i]], prop);
if(path) return props[i] + '.' + path;
}
return null;
}
var obj = {
object : {
client : {
name : 'Вася',
phone : '799999999'
},
order : {
param1 : '2122',
param2 : '1231'
}
}
};
console.log(findParamPath(obj, 'name')); // 'object.client.name'
console.log(findParamPath(obj, 'param1')); // 'object.order.param1'
console.log(findParamPath(obj, 'unknown')); // null (не найдено)
var http = require('http');
var ipTables = {};
var server = http.createServer((req, res) => {
//Ваш обработчик запроса или express/connect вместо него
});
server.on('connection', socket => {
var ip = socket.address().address;
var time = Date.now();
if(ip in ipTables) {
if(time - ipTables[ip].time > 3000) {
ipTables[ip] = {
count : 1,
time
};
return;
}
ipTables[ip].count++;
ipTables[ip].time = time;
if(ipTables[ip].count > 100) {
socket.end('HTTP/1.1 429 Too Many Requests\n\n');
socket.destroy(); //Обрываем соеденение, так как ip ломится слишком часто
}
return;
}
ipTables[ip] = {
count : 1,
time
};
});
server.listen(80);
this.items = [
{name : 'Petya', id: 1, active: false},
{name : 'Vasjya', id: 2, active: false},
{name : 'Dima', id: 3, active: false},
{name : 'Lena', id: 4, active: false},
{name : 'Katya', id: 5, active: false}
];
this.itemsIndex = _.indexBy(this.items, 'id');
this.items2 = [
{name : 'Dima', id: 3},
{name : 'Lena', id: 5},
];
this.items2.forEach(el => {
if(el.id in this.itemsIndex) {
this.itemsIndex[el.id].active = true;
}
});
function MainFoo () {
var myVar;
AsyncFoo().then(function(result) {
myVar = result;
});
}
function AsyncFoo() {
return new Promise(function(resolve, reject) {
setTimeout(function(){
resolve(100);
}, 5000)
});
}
async function MainFoo () {
var myVar = await AsyncFoo();
}
function AsyncFoo() {
return new Promise(function(resolve, reject) {
setTimeout(function(){
resolve(100);
}, 5000)
});
}