fetch()
надо ждать.var s = "36.000";
console.log(typeof s); // string
var n = +s;
console.log(typeof n); // number
console.log(n); // 36 нули после точки и не будет показывать – зачем
// показать ровно X позиций числа после точки:
var formatted = n.toFixed(3);
console.log(formatted); // 36.000 но это опять строка!
console.log(typeof formatted); // string
uncaught exception: We found an infinite loop in your Pen. We've stopped the Pen from running. Please correct it or contact support@codepen.io.
for(var i = 0; a.length; i++) {
// должно быть
for(var i = 0; i < a.length; i++) {
Date.parse()
съест и поймёт такую запись.const d = new Date('2020-02-14T11:40:44+03:00');
d.getFullYear(); // 2020
d.getMonth(); // 1 – месяцы считаются от 0 = январь
var a = document.getElementsByClassName('nosub');
назначает переменной a
значение: коллекцию HTML элементов. Если следующей строкой в консоли введёте просто a
, появится «подсказка» такая же как в первом варианте.for
, или методами массивов, например, forEach()
:[ ...document.getElementsByClassName('nosub')].forEach( el => el.style.display = "none" );
[...HTMLCollection]
это один из способов сделать из коллекции нормальный массив со всеми его методами, включая forEach()
. Подробнее см. spread syntax const handler = (e) => {
e.preventDefault();
const active = document.querySelector('.form-login__header-link.active');
const target = e.target;
if (target === active) return;
[register, login].forEach(el => el.classList.toggle('active'));
[...formContainer].forEach( el => el.classList.toggle('none'));
}
login.addEventListener('click', handler);
register.addEventListener('click', handler);
e.target
– кликнутый элемент. console.log()
.this
– ваш объект, а где становится «вдруг» window
:console.log("внутри timeout", this);
(callback) => { ... }
от обычных function() { ... }
this.response = function() { .. тут собственный this.. }
Когда передаёте аргументом ..(t.response)
, он улетает из контекста Window, поэтому в нём this == window
. this.response = () => { .. тут this на момент обращения к нему .. }
callback()
или this.data = "Steve Jobs"
?function test() {
this.data = null;
this.response = function() {
console.log(this, this.data);
}
this.connect = function(callback) {
setTimeout(() => {
this.data = "Steve Jobs";
callback.call(this);
}, 500);
}
}
t = new test();
t.connect(t.response);
The returned array also exposes a columns
property containing the column names in input order (in contrast to Object.keys, whose iteration order is arbitrary).
var a = [11,22];
a.columns = [333, 444];
JSON.stringify(a)
> "[11,22]"
JSON.stringify(a.columns)
"[333,444]"
A global environment record is logically a single record but it is specified as a composite encapsulating an object environment record and a declarative environment record. The object environment record has as its base object the global object of the associated Realm. This global object is the value returned by the global environment record’s GetThisBinding concrete method. The object environment record component of a global environment record contains the bindings for all built-in globals (clause 18) and all bindings introduced by a FunctionDeclaration, GeneratorDeclaration, or VariableStatement contained in global code.
The bindings for all other ECMAScript declarations in global code are contained in the declarative environment record component of the global environment record.
separator()
, если посмотреть исходник, принимает 3 аргумента: * @params {String} [separator=' '] string to separate number groups
* @params {String} [group_length=3] number group length
* @params {String} [suffix=''] suffix to append to number
var comma_separator_number_step = $.animateNumber.numberStepFactories.separator(' ', 3, ' руб.');
$
Ограничения на имена свойств
Мы можем использовать только строки и символы в качестве ключей свойств. Все другие типы данных будут автоматически преобразованы к строке.
Например, если использовать как ключ число 0, то оно превратится в строку "0"
{
const el1 = document.getElementById("block_1");
// второй div, предположу, пока не присутствует в разметке
// поэтому его надо создать:
const el2 = document.createElement("div");
el2.id = "block_2";
el2.innerText = "content 2";
// собственно, замена:
setTimeout(() => el1.parent.replaceChild(el2, el1), 3e3);
// или то же более современно, не работает в IE:
setTimeout(() => el1.replaceWith(el2), 3e3);
}
const data = {};
let us={id:124,room:10,string:"1_2_3_4_5_6_7_8_9_10-1"};
data[us.id] = [us.room,us.id,Nnum,bet];
const data = new Map();
data.set(us.id, [us.room,us.id,Nnum,bet]);
$(".item")[0].outerHTML
document.querySelector('.item').outerHTML