From IT Skills
Jump to: navigation, search

Javascript is not even a true programming language. It is a mess created by Netscape in a week! It is the worst language ever, and yet we run the world wide web on it! There are many modern and wonderful languages that the W3C could approve tomorrow morning as a new web standard... Mobile apps, videogames, video editing… in all those fields people are using SVG. Not mixed with HTML, Javascript and CSS. Just SVG.

Variables and scope[edit | edit source]

Глобальными называют переменные и функции, которые не находятся внутри какой-то функции. То есть, иными словами, если переменная или функция не находятся внутри конструкции function, то они – «глобальные».... Объект window одновременно является глобальным объектом и содержит ряд свойств и методов для работы с окном браузера

Variables defined with var inside a function scope .. don’t leak out of that scope... However, when you define variables with var in a block scope you can totally access them outside that scope... When defining variables with #let, we won’t have this weird out-of-scope access problem... Arrow functions give access to their defining environment while regular functions give access to their calling environment. This access is possible through the special this keyword... this keyword inside a regular function depends on how the function was called... The value of the this keyword inside an arrow function depends on where the function was defined... functions .call, .apply, and .bind can be used to change the calling environment

Все переменные внутри функции – это свойства специального внутреннего объекта LexicalEnvironment, который создаётся при её запуске... При создании функция получает скрытое свойство [[Scope]], которое ссылается на лексическое окружение, в котором она была создана... Иногда свойства, привязанные к функции, называют «статическими переменными»... Замыкание – это функция вместе со всеми внешними переменными, которые ей доступны.

hoisting — декларации всех используемых переменных переносятся в начало функции

let[edit | edit source]

var declarations have some odd scoping rules... var declarations are accessible anywhere within their containing function, module, namespace, or global scope - all which we’ll go over later on - regardless of the containing block. Some people call this var-scoping or function-scoping. Parameters are also function scoped... When a variable is declared using let, it uses what some call lexical-scoping or block-scoping. Unlike variables declared with var whose scopes leak out to their containing function, block-scoped variables are not visible outside of their nearest containing block or for-loop... Variables declared in a catch clause also have similar scoping rules. Another property of block-scoped variables is that they can’t be read or written to before they’re actually declared.

Shorthand and dynamic properties[edit | edit source]

const obj = {
  p1: 10,        // Plain old object property (don't abbreviate)

  f1() {},       // Define a shorthand function property

  InverseOfPI,   // Define a shorthand regular property

  f2: () => {},  // Define an arrow function property

  [mystery]: 42, // Define a dynamic property
};

mjs7.png

JavaScript will first evaluate the expression inside [] and whatever that expression evaluates to becomes the object’s new property. For the example above, the obj object will have a property answer with the value of 42.

Subcategories

This category has the following 3 subcategories, out of 3 total.

J

S

Pages in category "JS"

The following 11 pages are in this category, out of 11 total.