Array.prototype.inArray = function (item) {return this.indexOf(item) > -1}
indexOf()
, ни к чему изобретать велосипед. Но ее нужно вызвать ранее, не в конце.Ну так вызовите, кто ж вам не даёт? Только надо ещё все её зависимости перед этим загрузить.
var a = ['#one', '#two', '#three'];
var x = window.location.hash;
if (a.indexOf(x) < 0) {
console.log('nope');
}
Метод indexOf() возвращает первый индекс, по которому данный элемент может быть найден в массиве или -1, если такого индекса нет.
(x === '#one' || x === '#two' || x === '#three') !== true
x != '#one' && x != '#two' && x != '#three'
this.name
не то же самое, что Func.name
или Func.prototype.name
. Вы в конструкторе записываете свойство экземпляру объекта, а удалить пытаетесь из самого объекта.var func2 = new Func('hello');
delete func2.name;
func2.name // undefined
function Func(name) {
this.name = name;
}
Func.prototype.name = 'Foo';
var f = new Func('Bar');
console.log(f.name); // "Bar"
delete f.name;
console.log(f.name); // "Foo"
delete f.name;
console.log(f.name); // "Foo"
a.toUpperCase() === "Отгадка".toUpperCase()
var input = 'оТгАдКа';
var answer = new RegExp('^' + input + '$', 'i');
var correct = 'Отгадка';
if (answer.test(correct))
{
// correct
}
var put = function(elem, text) {
var text = encodeURIComponent(text);
return {
now: function(a) {
var a = encodeURIComponent(a) || '';
return {
add: function() {
elem.outerHTML += text + a;
},
replace: function() {
elem.outerHTML = text + a;
},
}
},
after: function(time) {
// do smth
},
}
}
put(document.getElementById("div_id"), "Hello ").now("world!").replace();
for (key in o ) {
if (!o.hasOwnProperty(key)) {
continue;
}
console.log(key, o[key]);
}
var i = 0;
while (true) {
if (i >= 5) {
// Здесь i равен 5
break;
}
console.log(i);
i++; // в тот момент, когда i становится равным 4-ём, цикл ещё работает и инкремент выполняется
}
console.log('after loop', i);
bot.on('message', httpGet(msg))
httpGet(
function(msg) {
var chatId = msg.chat.id;
console.log(msg);
bot.sendMessage(chatId, "Привет11", {
caption: "I'm a bot!"
});
return chatId;
}.then(sendM(chatId), function(chatId) {
return chatId;
})
);
var twoPoints = document.getElementById("twoPoints").textContent;