<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3386683896821079506</id><updated>2024-09-02T07:45:15.978+02:00</updated><category term="frontend"/><category term="JavaScript"/><category term="css"/><category term="praca"/><category term="function"/><category term="funkcja"/><category term="flex"/><category term="flexbox"/><category term="flexible box layout module"/><category term="zdjęcia"/><category term="przemyślenia"/><category term="wordpress"/><category term="IE7"/><category term="przeglądarki"/><category term="anonymous function"/><category term="domkniecia"/><category term="web developer"/><category term="ES6"/><category term="IE8"/><category term="ajax"/><category term="algorithms"/><category term="arrows"/><category term="backend"/><category term="browser"/><category term="closure"/><category term="codility"/><category term="css3 media queries"/><category term="funkcje anonimowe"/><category term="html5"/><category term="interview"/><category term="jquery"/><category term="kandydaci"/><category term="object"/><category term="opera"/><category term="react"/><category term="rekruterzy"/><category term="samowolajace sie"/><category term="scope"/><category term="self-invoking"/><category term="zatrudniamy"/><category term="Counting Elements"/><category term="ECMAScript 2015"/><category term="Explorer"/><category term="GMT"/><category term="IE"/><category term="IT"/><category term="Immediately Invoked Function Expressions"/><category term="Infinity"/><category term="Internet"/><category term="NaN"/><category term="OOP"/><category term="[Javascript Basics]"/><category term="align-items"/><category term="aplikacja"/><category term="apply"/><category term="array"/><category term="arrow function"/><category term="arytmetyczne"/><category term="basis"/><category term="biblioteka"/><category term="biuro"/><category term="border-collapse"/><category term="cache"/><category term="callback anonymous function"/><category term="category"/><category term="clone"/><category term="cookie"/><category term="deathmaze"/><category term="deep"/><category term="display"/><category term="document.cookie"/><category term="document.write"/><category term="domknięcie"/><category term="dzieci"/><category term="elements"/><category term="event"/><category term="fatal error"/><category term="funkcje prywatne"/><category term="game"/><category term="gap"/><category term="gildia"/><category term="gradient"/><category term="grow"/><category term="hooks"/><category term="hr"/><category term="humor"/><category term="image"/><category term="impreza"/><category term="inline"/><category term="inner function"/><category term="integracja"/><category term="justify-content"/><category term="kobieta"/><category term="kwiatki"/><category term="lexical scope"/><category term="li"/><category term="links"/><category term="lol"/><category term="magento"/><category term="map"/><category term="meta"/><category term="modyfikacje"/><category term="nauka"/><category term="null"/><category term="obiekt"/><category term="obiektowość"/><category term="obiekty"/><category term="object oriented programming"/><category term="oferta"/><category term="onLoad"/><category term="operacje"/><category term="order"/><category term="ordinal group"/><category term="outline"/><category term="overflow"/><category term="path"/><category term="plany"/><category term="plugin"/><category term="positioning on axis"/><category term="private function"/><category term="product"/><category term="programowanie"/><category term="przepisywanie sie funkcji"/><category term="puste miejsca"/><category term="reference"/><category term="referencja"/><category term="rodzina"/><category term="seo"/><category term="shrink"/><category term="sidebar"/><category term="space"/><category term="span"/><category term="split"/><category term="string"/><category term="submenu"/><category term="szkola"/><category term="szkolenie"/><category term="tekst"/><category term="time complexity"/><category term="time()"/><category term="tornister"/><category term="undefined"/><category term="useState"/><category term="viewport"/><category term="visible"/><category term="widget"/><category term="world of warcraft"/><category term="wpadki"/><category term="wrap"/><category term="yoast"/><category term="zakres leksykalny"/><category term="zakres statyczny"/><category term="zmiana"/><category term="zwracanie funkcji przez funkcje"/><category term="ścieżka"/><title type='text'>Kobieta w świecie IT</title><subtitle type='html'>Blog o technologiach frontend (javascript, html, css, react) oraz o tym co się zdarza w życiu informatyka.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>89</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-4088268431411671936</id><published>2021-02-02T17:07:00.000+01:00</published><updated>2021-02-02T17:07:13.952+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="null"/><category scheme="http://www.blogger.com/atom/ns#" term="undefined"/><title type='text'>undefined vs null</title><content type='html'>Ostatnio natknęłam się na artykuł stwierdzający, że &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;typeof null&lt;/span&gt; zwraca &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;&quot;object&quot;&lt;/span&gt; z powodu błędu w JavaScript. W ciągu ostatnich 20 lat pisania w różnych językach widziałam kilka błędów (np różna kolejność tych samych parametrów w funkcjach explode i implode w starym PHP) ale ta logika jest w JavaScript od początku i jakoś nie chce mi się wierzyć, że od ponad 20 lat nikt tego nie poprawił.&lt;br&gt;
&lt;br&gt;
Tak więc wzięłam się (po raz któryś z kolei) za czytanie dokumentacji na mdn. A tam stoi: &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null&quot; target=&quot;_blank&quot;&gt;The value null represents the intentional absence of any object value. It is one of JavaScript&#39;s primitive values and is treated as falsy for boolean operations.&lt;/a&gt;.&lt;br&gt;&lt;br&gt;

Co to oznacza w praktyce? A oznacza to, że jeśli nasz obiekt (lub cokolwiek co po nim dziedziczy) nie ma wartości i jest to zamierzone (np takiego użytkownika nie ma) to używamy &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;null&lt;/span&gt;. A co jeśli pracujemy ze stringiem? Wtedy zazwyczaj używamy &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;&quot;&quot;&lt;/span&gt;, żeby oznaczyć, że nie ma wartości, dla liczb dajemy &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;0&lt;/span&gt; a dla wartości logicznych &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;false&lt;/span&gt;.&lt;br&gt;&lt;br&gt;

Ten &lt;span style=&quot;background-color: rgb(206, 206, 206)&quot;&gt;null&lt;/span&gt; dla obiektów jest bardzo przydatny. Zapis &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;{}&lt;/span&gt; zwraca istniejącą wartość (jest obiekt, choć pusty), tak samo z &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;[]&lt;/span&gt;. Więc żeby zachować konwencję używania &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;!zmienna&lt;/span&gt; obiektom ustawiamy null, gdy celowo nie mają wartości.&lt;br&gt;&lt;br&gt;

Z &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;undefined&lt;/span&gt; historia jest trochę inna. To jest domyślna wartość używana przez JS gdy wartość czegoś nie została ustawiona (jeszcze). Warto utrzymać to rozróżnienie dla zwiększenia czytelności kodu.&lt;br&gt;&lt;br&gt;

&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;
  &lt;strong&gt;typeof {}&lt;/strong&gt; // &quot;object&quot;&lt;br&gt;
  &lt;strong&gt;typeof []&lt;/strong&gt; // &quot;object&quot;&lt;br&gt;
  &lt;strong&gt;typeof (() =&gt; {})&lt;/strong&gt; // &quot;function&quot;&lt;br&gt;&lt;br&gt;
  &lt;strong&gt;({}) instanceof Object&lt;/strong&gt; // true&lt;br&gt;
  &lt;strong&gt;new Object() instanceof Object&lt;/strong&gt; // true&lt;br&gt;
  &lt;strong&gt;([]) instanceof Object&lt;/strong&gt; // true&lt;br&gt;
  &lt;strong&gt;new Array() instanceof Object&lt;/strong&gt; // true&lt;br&gt;
  &lt;strong&gt;(() =&gt; {}) instanceof Object&lt;/strong&gt; // true&lt;br&gt;&lt;br&gt;
  &lt;strong&gt;!!null === false&lt;/strong&gt; // true&lt;br&gt;
  &lt;strong&gt;!null === true&lt;/strong&gt; // true&lt;br&gt;
  &lt;strong&gt;!!&quot;&quot; === false&lt;/strong&gt; // true&lt;br&gt;
  &lt;strong&gt;!&quot;&quot; === true&lt;/strong&gt; // true&lt;br&gt;
  &lt;strong&gt;!!0 === false&lt;/strong&gt; // true&lt;br&gt;
  &lt;strong&gt;!0 === true&lt;/strong&gt; // true&lt;br&gt;
&lt;/div&gt;

Dla zainteresowanych dodatkowy artykuł &lt;a href=&quot;https://2ality.com/2021/01/undefined-null-revisited.html&quot; target=&quot;_blank&quot;&gt;undefined vs. null revisited&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/4088268431411671936/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2021/02/undefined-vs-null.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/4088268431411671936'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/4088268431411671936'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2021/02/undefined-vs-null.html' title='undefined vs null'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-2932593248007319272</id><published>2020-10-19T21:26:00.001+02:00</published><updated>2020-10-28T17:36:34.865+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="hooks"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="react"/><category scheme="http://www.blogger.com/atom/ns#" term="useState"/><title type='text'>react hooks - useState</title><content type='html'>Hooki w react pojawiły się pod koniec 2018 roku. Umożliwjają one wygodne pisanie komponentów funkcyjnych, dzielenie odpowiedzialności w kodzie oraz tworzenie małych plików - łatwych w testowaniu, utrzymaniu i wygodnych, gdy trzeba znaleźć błąd.&lt;br&gt;&lt;br&gt;

Najbardziej podstawowym hookiem jest &lt;span style=&quot;background-color: rgb(206, 206, 206)&quot;&gt;useState()&lt;/span&gt;. Umożliwia on zarządzanie wartością stanu pomiędzy kolejnymi wywołaniami funkcji komponentu.&lt;br&gt;&lt;br&gt;

&lt;span style=&quot;background-color: rgb(206, 206, 206)&quot;&gt;useState()&lt;/span&gt; zwraca tablicę z dwiema wartościami: stanem i funkcją do jego aktualizacji. Zgodnie z konwencją nazwa funkcji do aktualizacji powinna zaczynać się od czasownika &lt;span style=&quot;background-color: rgb(206, 206, 206)&quot;&gt;set&lt;/span&gt;, czyli ustawiać. Jeśli zmienną stanu nazwiemy &lt;span style=&quot;background-color: rgb(206, 206, 206)&quot;&gt;user&lt;/span&gt; to funcja powinna nazywać się &lt;span style=&quot;background-color: rgb(206, 206, 206)&quot;&gt;setUser&lt;/span&gt;.&lt;br&gt;

&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;
  const &lt;strong&gt;[state, setState]&lt;/strong&gt; = useState(); 
&lt;/div&gt;&lt;br&gt;

&lt;span style=&quot;background-color: rgb(206, 206, 206)&quot;&gt;useState()&lt;/span&gt; przyjmuje jako parametr początkową wartość stanu&lt;br&gt;

&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;
  const [&lt;strong&gt;state&lt;/strong&gt;, setState] = useState(4);&lt;br&gt;
  console.log(&lt;strong&gt;state&lt;/strong&gt;); // &lt;strong&gt;4&lt;/strong&gt;
&lt;/div&gt;&lt;br&gt;

Funkcja &lt;span style=&quot;background-color: rgb(206, 206, 206)&quot;&gt;setState&lt;/span&gt; przyjmuje jako parametr nową wartość stanu lub callback&lt;br&gt;

&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;
  const [state, &lt;strong&gt;setState&lt;/strong&gt;] = useState(4);&lt;br&gt;
  console.log(state); // 4&lt;br&gt;
  &lt;strong&gt;setState(24)&lt;/strong&gt;;&lt;br&gt;
  console.log(state); // &lt;strong&gt;24&lt;/strong&gt;
&lt;/div&gt;&lt;br&gt;

Callback przyjmuje jako parametr aktualna wartość lub referencję stanu:&lt;br&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;
  const [state, &lt;strong&gt;setState&lt;/strong&gt;] = useState(4);&lt;br&gt;
  console.log(state); // 4&lt;br&gt;
  &lt;strong&gt;setState(state =&gt; state + 1)&lt;/strong&gt;;&lt;br&gt;
  console.log(state); // &lt;strong&gt;5&lt;/strong&gt;
&lt;/div&gt;&lt;br&gt;

Po co &lt;span style=&quot;background-color: rgb(206, 206, 206)&quot;&gt;setState&lt;/span&gt; przyjmuje callback jako parametr? Po to, żeby w każdym przypadku, gdy nasz kod nie ma dostępu do aktualnego &lt;span style=&quot;background-color: rgb(206, 206, 206)&quot;&gt;state&lt;/span&gt; móc jednak z niego korzystać. Dość toporny przykład pokazujący jak to działa jest z wykorzystaniem &lt;span style=&quot;background-color: rgb(206, 206, 206)&quot;&gt;setInterval&lt;/span&gt;&lt;br&gt;.

&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;
import React from &quot;react&quot;;&lt;br&gt;&lt;br&gt;

export default function App() {&lt;br&gt;
&amp;nbsp;&amp;nbsp;const [state, setState] = React.useState(0);&lt;br&gt;&lt;br&gt;

&amp;nbsp;&amp;nbsp;function updateState() {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;strong&gt;setState((state || 0) + 1)&lt;/strong&gt;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;}&lt;br&gt;&lt;br&gt;

&amp;nbsp;&amp;nbsp;React.useEffect(() =&gt; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;const interval = setInterval(updateState, 3000);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return () =&gt; clearInterval(interval);&lt;br&gt;
&amp;nbsp;&amp;nbsp;}, []);&lt;br&gt;&lt;br&gt;

&amp;nbsp;&amp;nbsp;return (&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div className=&quot;App&quot;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{console.log(&quot;rerender&quot;, state)}&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;h3&gt;{state}&amp;lt;/h3&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;);&lt;br&gt;
}
&lt;/div&gt;&lt;br&gt;

Powyższy przykład pokazuje ustawianie nowej wartości stanu co 3 sekundy. Niestety, stan ustawia się na 1, cały czas co 3 sekundy, ponieważ funkcja &lt;span style=&quot;background-color: rgb(206, 206, 206)&quot;&gt;updateState&lt;/span&gt; jest utworzona, gdy &lt;span style=&quot;background-color: rgb(206, 206, 206)&quot;&gt;state&lt;/span&gt; wynosi 0. I tak zostaje przekazana do &lt;span style=&quot;background-color: rgb(206, 206, 206)&quot;&gt;setInterval&lt;/span&gt;. Co 3 sekundy &lt;span style=&quot;background-color: rgb(206, 206, 206)&quot;&gt;setInterval&lt;/span&gt; zwieksza &lt;span style=&quot;background-color: rgb(206, 206, 206)&quot;&gt;state&lt;/span&gt; równy 0 o 1...&lt;br&gt;
&lt;a href=&quot;https://codesandbox.io/s/set-state-with-value-bnrx4&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;zobacz na Sandbox&lt;/a&gt;&lt;br&gt;&lt;br&gt;

Sposobem na naprawienie (poza zabawą scope i clojure) jest użycie callbacku jako parametru w &lt;span style=&quot;background-color: rgb(206, 206, 206)&quot;&gt;setState&lt;/span&gt;, wtedy cała funkcja bedzie wygladać tak:&lt;br&gt;

&lt;a href=&quot;https://codesandbox.io/s/set-state-with-callback-bnrx4&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;zobacz na Sandbox&lt;/a&gt;&lt;br&gt;&lt;br&gt;

&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;
&amp;nbsp;&amp;nbsp;function updateState() {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;strong&gt;setState(state =&gt; (state || 0) + 1)&lt;/strong&gt;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;}
&lt;/div&gt;&lt;br&gt;

&lt;span style=&quot;background-color: rgb(206, 206, 206)&quot;&gt;state&lt;/span&gt; przekazywany do callbacku jest tym aktualnym, wiec co 3 sekundy rośnie jego wartośc o 1.&lt;br&gt;</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/2932593248007319272/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2020/10/react-hooks-usestate.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/2932593248007319272'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/2932593248007319272'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2020/10/react-hooks-usestate.html' title='react hooks - useState'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-7558209919273767088</id><published>2020-10-19T21:20:00.001+02:00</published><updated>2020-10-19T21:20:37.286+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="obiekt"/><category scheme="http://www.blogger.com/atom/ns#" term="object"/><category scheme="http://www.blogger.com/atom/ns#" term="react"/><category scheme="http://www.blogger.com/atom/ns#" term="reference"/><category scheme="http://www.blogger.com/atom/ns#" term="referencja"/><title type='text'>react i referencja</title><content type='html'>Cykl życia komponentu reacta obejmuje update komponentu, gdy dane na których pracuje komp[onent się zmienią. Dotyczy to zarówno danych przychodzacych z zewnątrz (props) jak i tych tworzonych i uaktualnianych wewnątrz komponentu (state). Jeśli chodzi o dane prymitywne (liczby, ciągi tekstowe, typy logiczne, null, undefined i Symbol) to sprawa jest dość prosta. Wiadomo, że:&lt;br&gt;

&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;
  console.log(1 === 1); // true&lt;br&gt;
  console.log(&#39;a&#39; === &#39;a&#39;); // true&lt;br&gt;
  console.log(true === true); // true&lt;br&gt;
  console.log(undefined === undefined); // true&lt;br&gt;
  console.log(Symbol(&#39;a&#39;).toString() === Symbol(&#39;a&#39;).toString()); // true&lt;br&gt;
&lt;/div&gt;&lt;br&gt;

Czyli jeśli wartość props lub state zmieni się z 1 na 2 to komponent wie, że ma się zrerenderować. Proste.&lt;br&gt;&lt;br&gt;

A jednak, nie do końca. Wszystko co nie jest prymitywem w JS (jest to pewne uproszczenie, będzie osobny wpis na ten temat) jest obiektem. A obiekty nie są przekazywane przez wartość a przez referencję. Innymi słowy JS umieszcza utworzony obiekt gdzieś w pamięci i posługuje się adresem tego obiektu a nie nim samym. Każde utworzenie obiektu tworzy nową referencję.&lt;br&gt;

&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;
  const a = { id: 1 };&lt;br&gt;
  const b = { id: 1 };&lt;br&gt;&lt;br&gt;
  console.log(a === a); // true&lt;br&gt;
  console.log(a === b); // false&lt;br&gt;
  console.log(Object.is(a, a)); // true
  console.log(Object.is(a, b)); // false
&lt;/div&gt;&lt;br&gt;

Czyli nawet dwa identyczne obiekty mają dwie różne referencje, więc nie da się ich łatwo porównać. React do porównywania obiektów używa &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;Object.is()&lt;/span&gt;.&lt;br&gt;&lt;br&gt;

Dlatego, gdy zmieniamy jakąś wartość w obiekcie, powinniśmy stworzyć nową referencję, żeby react zauważył zmianę, na przykład tak:&lt;br&gt;

&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;
  const [formData, setFormData] = useState({});&lt;br&gt;&lt;br&gt;
  
  function handleChange(evt) {&lt;br&gt;
&amp;nbsp;&amp;nbsp;const id = evt.target.id;&lt;br&gt;
&amp;nbsp;&amp;nbsp;const value = evt.target.value;&lt;br&gt;&lt;br&gt;
  
&amp;nbsp;&amp;nbsp;const formCopy = &lt;strong&gt;{ ...formData }&lt;/strong&gt;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;formCopy[id] = value;&lt;br&gt;
&amp;nbsp;&amp;nbsp;setFormData(formCopy);&lt;br&gt;
  }
&lt;/div&gt;&lt;br&gt;

Alternatywnym sposobem może być używanie biblioteki jak &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%&quot;&gt;immutable.js&lt;/span&gt; aby każda zmiana w obiekcie zwracała nową referencję.
</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/7558209919273767088/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2020/10/react-i-referencja.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/7558209919273767088'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/7558209919273767088'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2020/10/react-i-referencja.html' title='react i referencja'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-1252077473485274705</id><published>2020-05-30T21:35:00.001+02:00</published><updated>2020-10-19T21:36:28.871+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="[Javascript Basics]"/><category scheme="http://www.blogger.com/atom/ns#" term="arrow function"/><category scheme="http://www.blogger.com/atom/ns#" term="arrows"/><category scheme="http://www.blogger.com/atom/ns#" term="function"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>Function vs arrow function</title><content type='html'>Arrow function came in 2015 together with new ECMAScript 5. It was a revolution! No more &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;var that = this;&lt;/span&gt; to be able to use parent context in a callback.&lt;br /&gt;&lt;br /&gt;

I really enjoyed this time and like others was using arrow functions everywhere. But 5 years later I started to hate arrow functions used as normal functions.&lt;br /&gt;&lt;br /&gt;

Code with one-liner functions and other variables:&lt;br&gt;

&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
  &lt;strong&gt;const&lt;/strong&gt; getData = dataKey =&gt; get(state, dataKey);&lt;br /&gt;
  &lt;strong&gt;const&lt;/strong&gt; makePlainObj = () =&gt; ({});&lt;br /&gt;
  &lt;strong&gt;const&lt;/strong&gt; doSth = ({ a, b }) =&gt; {console.log(b)};&lt;br /&gt;
  &lt;strong&gt;const&lt;/strong&gt; abc = { get: someFn };&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;

Code with normal functions:

&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
  &lt;strong&gt;function&lt;/strong&gt; getData(dataKey) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;return get(state, dataKey);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
  &lt;strong&gt;function&lt;/strong&gt; makePlainObj() {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;return {};&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
  &lt;strong&gt;function&lt;/strong&gt; doSth({ a, b }) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;console.log(b);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
  &lt;strong&gt;const&lt;/strong&gt; abc = { get: someFn };&lt;br /&gt;
&lt;/div&gt;&lt;br&gt;

Yes, second code is longer but at the same time much more readable. On first look it is visible what is a variable and what is a function. Also functions are hoisted when created as variables arrow functions are not.

</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/1252077473485274705/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2020/05/function-vs-arrow-function.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/1252077473485274705'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/1252077473485274705'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2020/05/function-vs-arrow-function.html' title='Function vs arrow function'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-5209898234691182097</id><published>2019-06-30T08:36:00.000+02:00</published><updated>2019-06-30T08:49:14.958+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="frontend"/><category scheme="http://www.blogger.com/atom/ns#" term="interview"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>JavaScript built-in functionality - be careful and read docs</title><content type='html'>JavaScript has a lot of very useful built-in functions, like &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;isNaN()&lt;/span&gt;, &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;parseInt()&lt;/span&gt;, &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;isFinite()&lt;/span&gt; and so on. Those functions are simple and single purpose pieces of code used very often.&lt;br /&gt;&lt;br /&gt;

The &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;isNaN()&lt;/span&gt; function takes only one argument - the value which should be checked and returns a boolean - true or false. The only purpose is to check if the value is &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;NaN&lt;/span&gt; - not a number value which could be returned by functions parsing numbers or by arithmetical operators. There is no other way to check if the value is &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;NaN&lt;/span&gt;, so this function is very important.&lt;br /&gt;&lt;br /&gt;

There is also other &#39;is&#39; function - &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;isFinite()&lt;/span&gt; which determines whether the passed value is a finite number. Also very important as some of the arithmetic operators can return &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;Infinity&lt;/span&gt; as a result of the operation and then &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;isNaN()&lt;/span&gt; returns false. It also takes only one argument - the value to be checked and returns boolean.&lt;br /&gt;&lt;br /&gt;

Another useful single purpose function is &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;parseInt()&lt;/span&gt;. It checks provided string if it could be the number and returns the number or &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;NaN&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;

As there are more than one numeral systems, this function accepts the radix as a second argument. There is &lt;b&gt;NO DEFAULT&lt;/b&gt; value for radix. If radix is falsy then the value itself is taken in consideration. Because we can use &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;Number(string)&lt;/span&gt; to determine whether the string is a number or not &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;parseInt()&lt;/span&gt; works in a slighty different way. In general it checks if the string starts with the number and returns this number till first non-numerical value.&lt;br /&gt;&lt;br /&gt;

&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
parseInt(&#39;1&#39;, 10); // 1&lt;br /&gt;
parseInt(&#39;1abc&#39;, 10); // 1&lt;br /&gt;
parseInt(&#39;1f0&#39;, 10); // 1&lt;br /&gt;
&lt;br /&gt;
parseInt(&#39;1f0&#39;, 16); // 496&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
The &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;parseFloat()&lt;/span&gt; built-in function works the same way, except it accepts only one argument - the value, as floats are decimals, so the numeral system is already known.&lt;br /&gt;&lt;br /&gt;

Both parseX functions are documented that the value should be a string but any value type works properly.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;

&lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;Array.prototype.map&lt;/span&gt; is a built-in Array method. It takes 2 arguments: a callback function and this. Returns the brand new array with the same number of elements as the array it was called upon with values produced by the callback function. Simple and beautiful.&lt;br /&gt;&lt;br /&gt;

It is very important to remember that callback function also accepts arguments. All of them are optional, as the logic for creating values for the new array could not depend on existing ones, but still the callback accepts arguments. The first one is a current value. For [1,7,11] it will be 1, then 7 and then 11. The second argument is index of the value - for 1 it will be 0, for 7 - 1 and for 11 - 2. The third argument is the array map was called upon.&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
[1,7,11].map(() =&gt; null); // [null, null, null]&lt;br /&gt;
[1,7,11].map((value) =&gt; value * 2); // [2, 14, 22]&lt;br /&gt;
[1,7,11].map((value, index) =&gt; value * index); // [0, 7, 22]&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
So what will happen if we want to use &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;parseFloat()&lt;/span&gt; as a callback for map?&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
[&#39;1&#39;,&#39;7&#39;,&#39;11&#39;].map(parseFloat); // [1, 7, 11]&lt;br /&gt;
[&#39;1.1&#39;,&#39;7.9876&#39;,&#39;11.444442&#39;].map(parseFloat); // [1.1, 7.9876, 11.444442]&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
Works like a charm!&lt;br /&gt;&lt;br /&gt;

So why &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;parseInt()&lt;/span&gt; doesn&#39;t work as expected?&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
[&#39;1&#39;,&#39;7&#39;,&#39;11&#39;].map(parseInt); // [1, NaN, 3]&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
What is a problem here? Let&#39;s test the values:&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
parseInt(&#39;1&#39;); // 1&lt;br /&gt;
parseInt(&#39;7&#39;); // 7&lt;br /&gt;
parseInt(&#39;11&#39;); // 11&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
It should work...&lt;br /&gt;&lt;br /&gt;

Everytime if something doesn&#39;t work as expected checking docs can save hours of tests. The second argument in &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;parseInt()&lt;/span&gt; is radix and what passes &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;map()&lt;/span&gt; as a second parameter to the callback? An index of the value...&lt;br /&gt;&lt;br /&gt;

So testing the values should look like that:&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
parseInt(&#39;1&#39;, 0); // 1&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
For index 0 value is &#39;1&#39;. The radix is falsy, so the value itself is taken in consideration. If value doesn&#39;t start with 0 decimal system is used.&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
parseInt(&#39;7&#39;, 1); // NaN&lt;br /&gt;
&lt;/div&gt;&lt;/br&gt;
For index 1 value is &#39;7&#39;. Proper radix value is between 2 and 36. Any value parsed with 1 as a radix is &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;NaN&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
parseInt(&#39;11&#39;, 2); // 3&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
For index 2 value is &#39;11&#39;. Radix 2 means binary: 2^0 + 2^1 = 3.&lt;br /&gt;&lt;br /&gt;

So everything works just as it should. To make the callback work as expected a small change is required:&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
[&#39;1&#39;,&#39;7&#39;,&#39;11&#39;].map((value) =&gt; parseInt(value, 10)); // [1, 7, 11]&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
It is not the newbie mistake. Such problems happen for seasoned developers, as they are not machines and don&#39;t store not used information like the order or all arguments for built-in functions. Using documentation during development process doesn&#39;t mean developer has no experience or knowledge. Using docs is a very good habit and the best possible practice which saves hours of bug fixing.&lt;br /&gt;&lt;br /&gt;

All recruitment processes which check the knowledge of docs are leading to such problems. General understanding of the language, what happens under the hood and problem solving skills and strategies (for example how to debug such bug) are more important than memorizing the documentation.&lt;br /&gt;&lt;br /&gt;

Good to read:&lt;br /&gt;
&lt;a href=&quot;https://kobietawit.blogspot.com/2019/02/swiadome-operacje-arytmetyczne-na.html&quot;&gt;operacje arytmetyczne w JS&lt;/a&gt; [polish]&lt;br /&gt;
&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt&quot;&gt;parseInt() - JavaScript | MDN&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map&quot;&gt;Array.prototype.map() - JavaScript | MDN&lt;/a&gt;&lt;br /&gt;
</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/5209898234691182097/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2019/06/javascript-built-in-functionality-be.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/5209898234691182097'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/5209898234691182097'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2019/06/javascript-built-in-functionality-be.html' title='JavaScript built-in functionality - be careful and read docs'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-3467359444225560601</id><published>2019-03-04T10:44:00.000+01:00</published><updated>2019-03-05T10:38:21.088+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="frontend"/><category scheme="http://www.blogger.com/atom/ns#" term="interview"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="object oriented programming"/><category scheme="http://www.blogger.com/atom/ns#" term="OOP"/><title type='text'>OOP - polimorfizm</title><content type='html'>Na wielu rozmowach kwalifikacyjnych, poza pytaniami o sam JavaScript padają pytania z ogólnej wiedzy o programowaniu. Czasami o best practices, czasami twarda wiedza, którą, jakby nie było trzeba znać, choć niektóre jej aspekty w JS są zupełnie nieużyteczne.&lt;br /&gt;&lt;br /&gt;

W zależności od doświadczenia osób pytających, można natrafić na przykład o pytanie czym jest &lt;i&gt;polimorfizm&lt;/i&gt; i jak się go implementuje w JS. Polimorfizm łączy się z nadpisywaniem (&lt;i&gt;override&lt;/i&gt;) metod obiektu i ich przeładowaniem (&lt;I&gt;overload&lt;/i&gt;).&lt;br /&gt;&lt;br /&gt;

Obecnie (bo w podręcznikach z których ja się uczyłam, tego podziału nie było) dzieli się polimorfizm, ze względu na implementację, na dynamiczny i statyczny. W JS można zaimplementować polimorfizm dymamiczny i dość często się go stosuje (choć mogę się założyć, że większość programistów nie ma pojęcia, że to co robią ma taką nazwę). Jednak nie do końca on wygląda jak w definicji, choćby dlatego, że JS nie implementuje metod i klas abstrakcyjnych ani interfejsów. Do tego nie ma w nim twardego typowania. I bardzo dobrze, bo JS to nie Java czy C++. Jak ktoś nie umie żyć bez tych wynalazków, to jest mnostwo języków kompilowanych, które je oferują.&lt;br /&gt;&lt;br /&gt;

Zgodnie z definicją - polimorfizm zakłada, że obiekty różnych klas korzystają z z jednej konkretnej metody. Załóżmy, że mamy samolot, pyłek, ptaka i muchę. Te 4 obiekty mają jedną wspólną właściwość - latają. Nieważne jak, ale latają. Załóżmy, że mamy funkcję, która oczekuje na &quot;latające&quot; obiekty i jedyne co robi, to wywołuje na nich metodę &lt;b&gt;lataj&lt;/b&gt;. W Javie, zazwyczaj się to implementuje za pośrednictwem interfejsu. Interfejs wymusza implementację konkretnych metod. W JS w komentarzach do prototypu lub klasy musimy napisać, że dana metoda musi być implementowana. Można również zaimplementować daną metodę by default, żeby rzucała wyjątek i przy dziedziczeniu nadpisywać ją tak, żeby przy używaniu jej w obiekcie, który umie latać nie było błędu&lt;br &gt;&lt;br /&gt;.</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/3467359444225560601/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2019/03/oop-polimorfizm.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/3467359444225560601'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/3467359444225560601'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2019/03/oop-polimorfizm.html' title='OOP - polimorfizm'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-5683094047957656362</id><published>2019-02-22T11:07:00.000+01:00</published><updated>2019-02-22T11:22:58.412+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="arytmetyczne"/><category scheme="http://www.blogger.com/atom/ns#" term="Infinity"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="NaN"/><category scheme="http://www.blogger.com/atom/ns#" term="operacje"/><title type='text'>świadome operacje arytmetyczne na zmiennych w JS</title><content type='html'>&lt;b&gt;NaN&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;

Każdy szanujący się programista JS wie, że jeśli chce wykonać operację arytmetyczną na dwóch zmiennych i co najmniej jedna z nich jest &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;undefined&lt;/span&gt; lub obiektem, to wynikiem takiego działania będzie &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;NaN&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
1 + undefined // NaN&lt;br /&gt;
undefined / 2 // NaN&lt;br /&gt;
3 * {} // NaN&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;

Tak samo będzie, jeśli operacja nie jest dodawaniem i żadnej z liczb nie da się sparsować do liczby (&lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;parseInt&lt;/span&gt; lub &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;parseFloat&lt;/span&gt;).&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
1 - &#39;jeden&#39; // NaN&lt;br /&gt;
&#39;dwa&#39; / 1 // NaN&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;Infinity&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;

dzielenie przez 0 lub przez null daje już inny wynik - &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;Infinity&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
3 / null // Infinity&lt;br /&gt;
4 / 0 // Infinity&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;Wartości logiczne&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;

Wartości logiczne (&lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;true&lt;/span&gt; i &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;false&lt;/span&gt;) są traktowane w operacjach arytmetycznych jak... 1 i 0...&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
3 / false // Infinity&lt;br /&gt;
3 / true // 3&lt;br /&gt;
8 * false // 0&lt;br /&gt;
8 * true // 8&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;Niebezpieczny string&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;

Dodawanie, w którym jedną z wartości jest string jest zamieniane na łączenie stringów. Druga wartość, nieważne, jaką ma oryginalną wartość, też jest transformowana do stringa&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
1 + &#39;1&#39; // &quot;11&quot;&lt;br /&gt;
1 + &#39;dwa&#39; // &quot;1dwa&quot;&lt;br /&gt;
null + &#39;undefined&#39; // &quot;nullundefined&quot;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
ale, każda inna operacja arytmetyczna już działa inaczej&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
3 * &#39;4&#39; // 12&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;Tablice&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;

Jeśli operacja arytmetyczna jest dodawaniem, to wszystko co między nawiasami kwadratowymi jest traktowane, jak string. Literalnie wszystko.&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
2 + [3] // &quot;23&quot;&lt;br /&gt;
2 + [3, 4] // &quot;23,4&quot;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
Zagnieżdżanie struktur nic nie daje:&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
2 + [3, [4, &#39;aaa&#39;, true, null, { a: 1}]] // &quot;23,4,aaa,true,,[object Object]&quot;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
Jeśli chcemy wykonać operację arytmetyczną inną niż dodawanie i co najmniej jedna ze zmniennych będzie tablicą, to sprawa się komplikuje. Jeśli tablica ma tylko jeden element i jego wartość jest typem prostym, to ta wartość jest brana pod uwagę w operacji arytmetycznej.&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
2 * [3] // 6&lt;br /&gt;
2 * [&#39;4&#39;] // 8&lt;br /&gt;
3 / [0] // Infinity&lt;br /&gt;
[&#39;cztery&#39;] * 2 // NaN&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;

Przy operacji arytmetycznej innej niż dodawanie, jeśli tablica ma więcej elementów, to wynik jest zawsze &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;NaN&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;

&lt;i&gt;wyjątki&lt;/i&gt;:&lt;br /&gt;&lt;br /&gt;

&lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;[true] - 1&lt;/span&gt; zwraca &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;NaN&lt;/span&gt; chociaż &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;true - 1&lt;/span&gt; daje 0.&lt;br /&gt;
&lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;3 / []&lt;/span&gt; zwraca &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;Infinity&lt;/span&gt; choć &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;[][0]&lt;/span&gt; daje &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;undefined&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Jak się chronić przed błędami?&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;

Jeśli operacje arytmetyczne mają dużą wagę i muszą być wykonywane w JS jedynym działającym sposobem jest sprawdzanie typu zmiennych na których dokonujemy operacji.&lt;br /&gt;&lt;br /&gt;

Funkcje typu &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;isFinite&lt;/span&gt; lub &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;isNaN&lt;/span&gt; są niestety ułomne.&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
isFinite(true) // true&lt;br /&gt;
isNaN(&#39;&#39;) // false&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
Jeśli czekamy na liczby, które nie są wynikiem innej operacji arytmetycznej operator &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;typeof&lt;/span&gt; załatwia sprawę&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
typeof true === &#39;number&#39; // false&lt;br /&gt;
typeof undefined === &#39;number&#39; // false&lt;br /&gt;
typeof null === &#39;number&#39; // false&lt;br /&gt;
typeof &#39;1&#39; === &#39;number&#39; // false&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
Jeśli natomiast wchodzące dane są wynikiem innych operacji arytmetycznych (czyli ich wartość moze być &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;NaN&lt;/span&gt;), to trzeba pamiętać, że:&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
typeof NaN === &#39;number&#39; // true&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
więc należy sprawdzić, czy to co wchodzi nie jest &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;NaN&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
isNaN(NaN) // true&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/5683094047957656362/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2019/02/swiadome-operacje-arytmetyczne-na.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/5683094047957656362'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/5683094047957656362'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2019/02/swiadome-operacje-arytmetyczne-na.html' title='świadome operacje arytmetyczne na zmiennych w JS'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-6244053196730718049</id><published>2017-11-13T16:42:00.001+01:00</published><updated>2017-11-13T17:56:32.643+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="closure"/><category scheme="http://www.blogger.com/atom/ns#" term="domkniecia"/><category scheme="http://www.blogger.com/atom/ns#" term="domknięcie"/><category scheme="http://www.blogger.com/atom/ns#" term="frontend"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>Domknięcie (closure), co to jest i z czym to się je?</title><content type='html'>Na stronie MDN jest taka definicja &lt;i&gt;A closure is the combination of a function and the lexical environment within which that function was declared.&lt;/i&gt; Pamiętam, jak przeczytałam ją pierwszy raz. Jak to mawiała moja mama &quot;mózg mi stanął w poprzek&quot;. Każde słowo z osobna wydawało mi się co najmniej znajome, nawet jeśli nie w 100% zrozumiałe. Ale wszystkie do kupy powodowały, że mi się odechciewało.&lt;br /&gt;&lt;br /&gt;

To było wiele lat temu. Wiele lat, w trakcie których wciąż od nowa odkrywałam definicję &lt;i&gt;domknięcia&lt;/i&gt;. Wczoraj robiłam proste zadanko, podpięcie pod kolumnę z danymi numerycznymi sortowania po liczbach a nie alfabetycznie (żeby 70 było mniejsze niż 320). Metodę napisałam dość banalną:&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
function sort(a, b, order) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;return order === &#39;desc&#39; ?&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;parseFloat(a.balance) - parseFloat(b.balance) :&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;parseFloat(b.balance) - parseFloat(a.balance);&lt;br /&gt;
};&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;

Zadowolona z wyniku wzięłam się za testowanie. Już po chwili odkryłam, że poza kolumną opisaną w zadaniu, w tabeli jest więcej sortowalnych kolumn z danymi numerycznymi. Moja metoda, która świetnie spełniała swoje zadanie, dla jednej konkretnej kolumny, nie będzie działać, dla dowolnej innej kolumny, ponieważ sortuję wartości ukryte we właściwości &lt;i&gt;balance&lt;/i&gt; (&lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;a.balance&lt;/span&gt; i &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;b.balance&lt;/span&gt;). Dla innych kolumn potrzebowałam bardziej elastycznego rozwiązania.&lt;br /&gt;&lt;br /&gt;

Najłatwiej byłoby dodać nazwę kolumny, do argumentów funkcji. Ale interface funkcji przewidywał 3 konkretne argumenty: pierwszą wartość do sortowania, drugą wartość do sortowania oraz kierunek sortowania. I tu właśnie na pomoc przyszło mi domknięcie.&lt;br /&gt;&lt;br /&gt;

Ponieważ nie mogę przekazać do mojej funkcji nazwy właściwości, która przechowuje wartość do sortowania, muszę sprawić, żeby moja funkcja została stworzona w środowisku, które już zna tę nazwę. Ten przykład jasno pokazuje o co mi chodzi:&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
var name = &#39;Ania&#39;;&lt;br /&gt;&lt;br /&gt;

function greeting() {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;console.log(&#39;hello &#39; + name);&lt;br /&gt;
}&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;

Wewnątrz funkcji &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;greeting&lt;/span&gt; użyta jest zmienna &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;name&lt;/span&gt; utworzona na zewnątrz funkcji. Tego typu działanie nazywa się &lt;i&gt;scope&lt;/i&gt;, wszystko to co jest stworzone na zewnątrz funkcji jest widoczne wewnątrz, ale jeśli coś zostało stworzone wewnątrz (z użyciem któregoś ze słów kluczowych &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;var&lt;/span&gt;, &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;let&lt;/span&gt; lub &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;const&lt;/span&gt;) nie jest widoczne na zewnątrz.&lt;br /&gt;&lt;br /&gt;

Czyli potrzebuję stworzyć środowisko, w którym znana będzie nazwa właściwości która przechowuje wartość do sortowania. Do tego środowiska będę przekazywać tę nazwę (w każdej kolumnie będę korzystać z innej właściwości):&lt;br /&gt;&lt;br /&gt;

&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
function sortByPropName(propName) {}&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;

Środowisko już jest, wnętrze funkcji będzie znało wartość przekazanego tam argumentu &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;propName&lt;/span&gt;, jednak ja do tabeli mam przekazać funkcję, która bedzie przyjmować 3 konkretne argumenty.&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
function sortByPropName(propName) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;return function(a, b, order) {}&lt;br /&gt;
}&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;

Coś zaczyna z tego wychodzić. Mam już funkcję z potrzebnymi danymi, która zwraca inną funkcję, która oczekuje argumenty wyspecyfikowane w interfejsie. Teraz wystarczy dodać samą logikę, która uwzględnia przekazaną nazwę właściwości przechowujacej wartość do sortowania:&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
function sortByPropName(propName) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;return function(a, b, order) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return order === &#39;desc&#39; ?&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;parseFloat(a[propName]) - parseFloat(b[propName]) :&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;parseFloat(b[propName]) - parseFloat(a[propName]);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;}&lt;br /&gt;
}&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;

Wygląda nieźle, prawda? To teraz wystarczy przekazać wynik &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;sortByPropName&lt;/span&gt; jako funkcję sortujacą dla kolumny (kod jsx):&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
&amp;lt;TableHeaderColumn dataField=&quot;balance&quot; dataFormat={signedNumber} dataSort sortFunc={&lt;b&gt;sortByPropName(&#39;balance&#39;)&lt;/b&gt;}&amp;gt;Balance&amp;lt;/TableHeaderColumn&amp;gt;&lt;br /&gt;
&amp;lt;TableHeaderColumn dataField=&quot;total_amount&quot; dataFormat={signedNumber} dataSort sortFunc={&lt;b&gt;sortByNumericValue(&#39;total_amount&#39;)&lt;/b&gt;}&amp;gt;Total amount&amp;lt;/TableHeaderColumn&amp;gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;

Powyższy kod używa HTML wewnątrz JS, ale nie jak ciągu tekstowego, a bardziej jak obiektów XML. To co jest najważniejsze, to &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;sortFunc&lt;/span&gt;, do której przekazuję WYNIK działania &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;sortByPropName&lt;/span&gt;. &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;sortFunc&lt;/span&gt; oczekuje na funkcję sortującą, która będzie przyjmowała 3 argumenty, czyli dokładnie to, co zwraca &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;sortByPropName&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;

A gdzie w tym wszystkim jest domknięcie?&lt;br /&gt;&lt;br /&gt;

Dokładnie w tym, co zwraca &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;sortByPropName&lt;/span&gt;. Wartość argumentu &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;propName&lt;/span&gt; jest znana tylko wewnątrz funkcji, gdzie jest tworzona kolejna funkcja, która z tej wartości korzysta. Tę funkcję zwracamy na zewnątrz, gdzie jest przypisana do nazwy &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;sortFunc&lt;/span&gt; i wykorzystana wewnątrz komponentu &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;TableHeaderColumn&lt;/span&gt;. Pomimo, że &lt;span style=&quot;display:inline-block;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;sortFunc&lt;/span&gt; jest używana w zupełnie innym środowisku, ma dostęp do zmiennych ze środowiska, w którym została stworzona. To jest właśnie domknięcie.

&lt;br /&gt;



</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/6244053196730718049/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2017/11/domkniecie-closure-co-to-jest-i-z-czym.html#comment-form' title='Komentarze (2)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/6244053196730718049'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/6244053196730718049'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2017/11/domkniecie-closure-co-to-jest-i-z-czym.html' title='Domknięcie (closure), co to jest i z czym to się je?'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-9027764339919156361</id><published>2017-08-22T13:58:00.000+02:00</published><updated>2017-09-25T12:50:59.576+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="nauka"/><category scheme="http://www.blogger.com/atom/ns#" term="oferta"/><category scheme="http://www.blogger.com/atom/ns#" term="szkolenie"/><title type='text'>Oferty szybkiej nauki programowania - przestroga</title><content type='html'>Przeglądając maile natrafiłam na reklamę &quot;coders lab&quot;, szkoły programowania. Jako, ze mój syn w sposób dość intensywny pracuje nad swoimi umiejętnościami w zakresie programowania w JavaScript z dużym zainteresowaniem przejrzałam stronę. Marketing mają niezły, ofertę wpisującą się w moje potrzeby, ale... diabeł tkwi w szczegółach.&lt;br /&gt;&lt;br /&gt;

Na studiach psychologicznych każdy student wcześniej czy później styka się z teorią krzywej uczenia się. Otóż ta teoria zakłada, że uczenie się jest PROCESEM i, jak każdy proces, wzmaga CZASU. Procesem składającym się z kilku faz. Najważniejsze są dwie: faza zdobywania nowej wiedzy i faza utrwalania (tzw plateau), kiedy krzywa jest zupełnie płaska, bo podczas utrwalania nie jesteśmy w stanie realnie nauczyć się niczego nowego, bo zdobywamy doświadczenie w nowo zdobytej wiedzy. Realnie krzywa ma kształt najbardziej zbliżony do schodów.&lt;br /&gt;&lt;br /&gt;

Znając teorie uczenia się, posuwamy się z Młodym, w nauce, pozornie żółwim tempem. Na tę chwilę wciąż jesteśmy na etapie czystego JS. Żadnych bibliotek, same zasady kierujące językiem, który poznaje. Typy danych i wbudowane obiekty mamy omówione. W ramach utrwalania tej wiedzy (faza plateau) Młody przerabia metody należące do prototypu różnych obiektów. I tak wiem, ze więcej nie zrobi, więc niech zdobywa doświadczenie w zakresie nowo poznanej wiedzy. Na tę chwilę trwa to już kilka tygodni, ale Młody ma wiedzę utrwalona. Pytania o to, jak działa &lt;i&gt;scope&lt;/i&gt; czy jak zmienić kontekst w jakim wykonywana jest funkcja nie stanowią już dla niego wyzwania. Wiedza utrwaliła się.&lt;br /&gt;&lt;br /&gt;

Coders lab niestety hołduje zasadzie im szybciej tym lepiej. Jednym z interesujących mnie kursów z ich oferty jest &quot;JavaScript developer: React&quot;. Kurs trwa 30 dni, w opisie stoi: &quot;Kurs od podstaw odpowiedni dla tych, którzy wcześniej nie mieli styczności z programowaniem. Spodoba się osobom, które lubią zagadki logiczne i wolą skupić się na tym, jak coś działa niż na tym, jak wygląda[...]&quot;. Gdzieś w tym momencie przestałam rozumieć ofertę. Kurs oferuje naukę od podstaw, dla osób, które nigdy wcześniej nie miały styczności z programowaniem. Zgodnie z tytułem jest to kurs JavaScript rozszerzony o bibliotekę react. I trwa 30 dni. Nauka samego JavaScriptu to kilka miesięcy. React to też co najmniej kilka następnych tygodni. Bo przecież nie chodzi o samą znajomość składni czy używanych metod, a o zrozumienie, JAK i DLACZEGO to działa.&lt;br /&gt;&lt;br /&gt;

Hasłem przewodnim strony jest: &quot;W Coders Lab zmieniamy edukację – w ciągu 3 miesięcy zostaniesz junior developerem&quot;. Junior developer nie musi mieć doświadczenia (stąd junior), nie musi znać zaawansowanych przypadków użycia, opracować rozwiązań skomplikowanych problemów. Junior MUSI rozumieć język i technologie, w których pracuje. Musi mieć podstawy umożliwiające mu rozwijanie wiedzy. React jest biblioteką napisaną w czystym JS. Jest tylko biblioteką, żeby react zadziałał, programista sam musi napisać kod, który skorzysta z reacta i wynikiem działania napisanego kodu będzie to, co programista chciał osiągnąć. React jest NARZĘDZIEM, którego używa się za pośrednictwem JavaScriptu, wiec żeby zostać junior developerem kandydat musi znać co najmniej bardzo dobrze JavaScript. Musi rozumieć jak działa interpreter (w przeglądarce i na serwerze - nodejs), jak JS buduje &lt;i&gt;scope&lt;/i&gt;, czym jest kontekst. Musi znać i swobodnie używać metod obiektów wbudowanych (tablice, plain obiekty, Date, JSON). Musi widzieć dlaczego &lt;i&gt;null&lt;/i&gt; jest specjalny i jak i kiedy go używać.&lt;br /&gt;&lt;br /&gt;

Powyższe zagadnienia są poruszane podczas rozmów kwalifikacyjnych, na stanowiska związane z JS. Bibliotek można szybko się nauczyć, a to są podstawy samego języka i są wymagane, żeby w ogóle zacząć pracę z bibliotekami.&lt;br /&gt;&lt;br /&gt;

W szczegółach kursu stoją technologie, które wchodzą w jego skład: &lt;b&gt;HTML, CSS, JavaScript, jQuery, React, Gulp, Sass, RWD&lt;/b&gt;. Dobór trochę z Księżyca. Skoro kurs skupia się na logice a nie na prezentacji (jak jest opisane) to po co CSS, SASS i RWD? Po co komu jQuery do reacta? I co z tym wszystkim ma wspólnego gulp? I dlaczego nie ma webpacka i babel? I gdzie jest ES6/7/8?&lt;br /&gt;&lt;br /&gt;

Podsumowując. Te, i wszystkie podobne im szkolenia, muszą być dokładnie przejrzane przez kogoś, kto ma rozległą wiedzę z tematu. I cały czas należy pamiętać, że nie da się przyswoić większej ilości wiedzy w krótkim czasie, tak by ta wiedza została i służyła. Dlatego nauka w szkole trwa 12 lat a nie 4, mimo, ze dzieci uczą się szybciej. Zdobywanie wiedzy polega również na powtarzaniu i używaniu świeżo zdobytych umiejętności, wiec powracanie do wcześniej przerobionego materiału jest niezbędne. A to wszystko wymaga czasu.&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/9027764339919156361/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2017/08/oferty-szybkiej-nauki-programowania.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/9027764339919156361'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/9027764339919156361'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2017/08/oferty-szybkiej-nauki-programowania.html' title='Oferty szybkiej nauki programowania - przestroga'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-5002933386406814287</id><published>2017-07-20T13:54:00.000+02:00</published><updated>2017-07-20T13:54:09.381+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="anonymous function"/><category scheme="http://www.blogger.com/atom/ns#" term="browser"/><category scheme="http://www.blogger.com/atom/ns#" term="domkniecia"/><category scheme="http://www.blogger.com/atom/ns#" term="frontend"/><category scheme="http://www.blogger.com/atom/ns#" term="Immediately Invoked Function Expressions"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="scope"/><title type='text'>example how and what for to use anonymous functions</title><content type='html'>I wrote some short introduction to anonymous function &lt;a href=&quot;http://kobietawit.blogspot.de/2012/10/funkcje-w-javascript-part-2-funkcje.html&quot;&gt;here&lt;/a&gt;, some time ago. I wrote some simple example, but no example for real life situation. Today I decided to write down an example which could be very useful on technical interview.&lt;br /&gt;&lt;br /&gt;

This is a very simple code example. We have a loop and inside this loop we create an array of functions. Every of functions logs &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;i&lt;/span&gt; on the console. Then in the end we are calling the first function from the array.&lt;br /&gt;&lt;br /&gt;

&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
var i = 0;&lt;br /&gt;
var funcArray = [];&lt;br /&gt;
for (; i &lt; 20; i += 2) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;funcArray.push(function() {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;console.log(&#39;i inside function&#39;, i);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;};&lt;br /&gt;
});&lt;br /&gt;&lt;br /&gt;
funcArray[0]();&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;

What we want to achieve here is, to have an array of functions, to use inside of function a value of &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;i&lt;/span&gt;. We cannot use index of function in array, as &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;i&lt;/span&gt; is incremented by 2. This implementation looks like the easiest solution for our need.&lt;br /&gt;&lt;br /&gt;

So what would display on console as a result of this line &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;funcArray[0]();&lt;/span&gt;? We expect it to be &lt;i&gt;0&lt;/i&gt;, but unfortunately it is... &lt;i&gt;20&lt;/i&gt;... WHY??&lt;br /&gt;&lt;br /&gt;

The answer is very easy - &lt;b&gt;the scope&lt;/b&gt;. The thing which makes JavaScript harder to learn. But is very logic. Scope exists on function level (ES5) or on block level (ES6+). In this case inside of loop the function which uses scope variable &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;i&lt;/span&gt; is created. But the function is called outside the loop, where &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;i&lt;/span&gt; has a value &lt;i&gt;20&lt;/i&gt; (the first value, which didn&#39;t meet the requirement, so there was no more incrementation of &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;i&lt;/span&gt;).&lt;br /&gt;&lt;br /&gt;

So it doesn&#39;t matter which index would be called, the &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;i&lt;/span&gt; outside of loop is always equal the first value, which didn&#39;t pass the condiition. It means we have to change the way how we create the scope for our function. And here the anonymous function will come with help.&lt;br /&gt;&lt;br /&gt;

What should be done, then? We have to create immediately invoked anonymous function, which will create the scope and will return the function which will be assigned to array element. As a parameter to anonymous function &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;i&lt;/span&gt; will be passed to make it available inside the scope.&lt;br /&gt;&lt;br /&gt;

&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
funcArray.push(( // immediately invoked function&lt;br /&gt;
// anonymous function, which gets i from scope as index&lt;br /&gt;
&amp;nbsp;&amp;nbsp;function (index) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return function() { // returns a our function&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;console.log(&#39;index inside function&#39;, index);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;
&amp;nbsp;&amp;nbsp;}&lt;br /&gt;
)(i)); // i passed to immediately invoked function&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/5002933386406814287/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2017/07/example-how-and-what-for-to-use.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/5002933386406814287'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/5002933386406814287'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2017/07/example-how-and-what-for-to-use.html' title='example how and what for to use anonymous functions'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-5581082593825544164</id><published>2017-07-12T15:37:00.001+02:00</published><updated>2017-07-12T15:37:49.045+02:00</updated><title type='text'>pojęcie o zawodzie programisty wśród młodzieży</title><content type='html'>Ostatnio na Facebook trafiłam na taką wypowiedź:&lt;br /&gt;&lt;br /&gt;

&lt;i&gt;Chciałabym poznać opinię.
Zaczęłam się interesować samorozwojem i stwierdziłam że branża it jest najwlasciwsza dla mnie. No i super rozeznanie w terenie co jak po co. Sprawdzałam wyksztalcenie, doświadczenie, wiek no wszystko co trzeba. Stwierdziłam że może maturę będę potrzebować więc dałam zapytanie na lokalnej grupie o maturę w uk jak tu zdac, warunki etc. Koleżanka która pomaga czasem innym w sprawach counsil/ revenue/ inne urzędy poradziła mi gdzie się udać i zabiła mnie pytaniem .... A nie lepiej dla Ciebie jakbyś się wzięła za fryzjerstwo czy paznokcie??? ... No kurde. Ja jej mówię o tym że chce programować strony komputerowe, pisać aplikację, generalnie branża no wiadomo, A ta wypala o ee paznokciach? Wlosach? Jak ja kurde miałam raz tipsy na rękach z 8 lat temu a o makijażu mam takie pojęcie że otynkowanie zaczynamy od fluidu pudru czy czegoś. Czy ja przesadzam czy mi się wydaje?&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;

Napisałam panience, że niestety wykształcenie, jeśli nie ma odpowiedniego doświadczenia, jest niezbędne. W odpowiedzi dostałam link do holenderskiej oferty dla juniora frontendowca bez wymagań związanych z wykształceniem/doświadczeniem oraz taki tekst:&lt;br /&gt;&lt;br /&gt;

&lt;i&gt;Zresztą nie będę wiedzieć jeśli nie sprobuje. Nikt i nic mnie nie zniechęci Bo &quot;gdzieś tam potrzebują szkoly&quot;. Do firmy kolegi na stanowisko junior chcieli wziąć chłopaka po 4 tyg kursie za który sami zaplacili. Także ten.&lt;/i&gt;

I już sama nie wiem, czy to powszechne podejście do zawodu programisty? Pracowałam już z ludźmi, dla których hasło &quot;złożoność obliczeniowa&quot; było zbędnym i wymyślonym na siłę problemem, nad którym nie warto się pochylić...</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/5581082593825544164/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2017/07/pojecie-o-zawodzie-programisty-wsrod.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/5581082593825544164'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/5581082593825544164'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2017/07/pojecie-o-zawodzie-programisty-wsrod.html' title='pojęcie o zawodzie programisty wśród młodzieży'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-4916888339048277907</id><published>2017-07-12T13:48:00.000+02:00</published><updated>2017-07-12T13:48:55.835+02:00</updated><title type='text'>deadline&#39;y...</title><content type='html'>Pracuję sobie w firmie, takim prawie prawdziwym startupie. Prawie, bo mamy bogatą firmę-matkę, która łoży na nasze utrzymanie.&lt;br /&gt;&lt;br /&gt;

Piszemy aplikację WWW, backend dostarcza nam trzecia firma. Ja zajmuję się dość krytyczną częścią, bo zapisem danych wprowadzonych przez przyszłego klienta. Tworzę z mozołem DTO, które mam później pchnąć do backendu i odkrywam, że czegoś nie wiem.&lt;br /&gt;&lt;br /&gt;

Pierwsze pytanie do naszego konsultanta z firmy trzeciej, który siedzi z nami w open space. Pada odpowiedź - &lt;i&gt;nie da się, już rozmawiałem z działem wdrożeniowym i tej funkcjonalności na razie nie ma.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;

Nogi się pode mną ugięły. Jak to nie ma? Toż to krytyczna funkcjonalność... &lt;i&gt;Idź do XYZ i z nim pogadaj&lt;/i&gt; dostaję dobrą radę i konsultant zakłada słuchawki.&lt;br /&gt;&lt;br /&gt;

Idę, ale do S, naszego product ownera, i mówię, że mamy bloker. Już nawet się oparłam dodania, że to kolejny. &lt;i&gt;No co ty nie powiesz&lt;/i&gt; krzywi się S i uderza do konsultanta, który odsyła go do XYZ.&lt;br /&gt;&lt;br /&gt;

S właśnie wrócił do mnie z wiadomością, że &lt;i&gt;it is not in scope&lt;/i&gt;. A soft launch mamy w pierwszej połowie sierpnia, to ciekawie kiedy trafi do implementacji?
</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/4916888339048277907/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2017/07/deadliney.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/4916888339048277907'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/4916888339048277907'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2017/07/deadliney.html' title='deadline&#39;y...'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-1994774425004234355</id><published>2016-07-01T14:29:00.000+02:00</published><updated>2016-07-01T14:30:11.250+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="clone"/><category scheme="http://www.blogger.com/atom/ns#" term="deep"/><category scheme="http://www.blogger.com/atom/ns#" term="ES6"/><category scheme="http://www.blogger.com/atom/ns#" term="frontend"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="object"/><title type='text'>shallow and deep cloning objects in JavaScript</title><content type='html'>As all values in JavaScript are pass by reference clonig is quite popular operation, to save original object. Unfortunately JavaScript does not provide any method to clone deeply the whole object.&lt;br&gt;&lt;br&gt;

ES6 provided some features, which could be useful, but still we have to remember, that this is only a shallow cloning.&lt;br&gt;&lt;br&gt;

The first solution is to use &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign&quot; _target=&quot;blank&quot;&gt;Object.assign&lt;/a&gt;:&lt;br&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
const a = {&lt;br&gt;
&amp;nbsp;&amp;nbsp;b: {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;c: 1&lt;br&gt;
&amp;nbsp;&amp;nbsp;},&lt;br&gt;
&amp;nbsp;&amp;nbsp;z: 15&lt;br&gt;
};&lt;br&gt;
&lt;br&gt;
console.log(a); // {&quot;b&quot;:{&quot;c&quot;:1},&quot;z&quot;:15}&lt;br&gt;
&lt;br&gt;
let d = Object.assign({}, a);&lt;br&gt;
&lt;br&gt;
d.b.c = 5;&lt;br&gt;
d.z = 29;&lt;br&gt;
&lt;br&gt;
console.log(a); // {&quot;b&quot;:{&quot;c&quot;:5},&quot;z&quot;:15}&lt;br&gt;
console.log(d); // {&quot;b&quot;:{&quot;c&quot;:5},&quot;z&quot;:29}&lt;br&gt;
&lt;/div&gt;&lt;br&gt;

The first console.log will display original a object, but in the second a.b.c value will be changed. Only a.z value will stay the same. This is what shallow cloning is. Only first level properties are cloned, rest is passed by reference.&lt;br&gt;&lt;br&gt;

So what would happen if d.b would be changed?&lt;br&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
d.b = 118;&lt;br&gt;
&lt;br&gt;
console.log(a); // {&quot;b&quot;:{&quot;c&quot;:5},&quot;z&quot;:15}&lt;br&gt;
console.log(d); // {&quot;b&quot;:118,&quot;z&quot;:29}&lt;br&gt;
&lt;/div&gt;&lt;br&gt;

The same situation will happen if we will use spread operator:&lt;br&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
const aa = {&lt;br&gt;
&amp;nbsp;&amp;nbsp;g: {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;h: 1&lt;br&gt;
&amp;nbsp;&amp;nbsp;},&lt;br&gt;
&amp;nbsp;&amp;nbsp;y: 15&lt;br&gt;
};&lt;br&gt;
&lt;br&gt;
console.log(aa); // {&quot;g&quot;:{&quot;h&quot;:1},&quot;y&quot;:15}&lt;br&gt;
&lt;br&gt;
let e = { ...aa };&lt;br&gt;
&lt;br&gt;
e.g.h = 9;&lt;br&gt;
e.y = 23;&lt;br&gt;

console.log(aa); // {&quot;g&quot;:{&quot;h&quot;:9},&quot;y&quot;:15}&lt;br&gt;
&lt;/div&gt;&lt;br&gt;

So, how to make a deep cloning in JavaScript?&lt;br&gt;&lt;br&gt;

1. Use JSON stringify and parse&lt;br&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
JSON.parse(JSON.stringify(object));
&lt;/div&gt;&lt;br&gt;

2. Write own method to do a deep clone of passed object.&lt;br&gt;&lt;br&gt;</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/1994774425004234355/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2016/07/clone-and-deep-clone-of-objects-in.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/1994774425004234355'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/1994774425004234355'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2016/07/clone-and-deep-clone-of-objects-in.html' title='shallow and deep cloning objects in JavaScript'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-6504908913016889768</id><published>2015-09-03T07:37:00.002+02:00</published><updated>2015-09-03T07:43:16.686+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="arrows"/><category scheme="http://www.blogger.com/atom/ns#" term="ECMAScript 2015"/><category scheme="http://www.blogger.com/atom/ns#" term="ES6"/><category scheme="http://www.blogger.com/atom/ns#" term="frontend"/><category scheme="http://www.blogger.com/atom/ns#" term="function"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>ES6 - arrows</title><content type='html'>The biggest difference between arrow and function is &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;this&lt;/span&gt; value. Function uses its own &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;this&lt;/span&gt; value, but arrow uses &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;this&lt;/span&gt; value of the enclosing context.&lt;br&gt;&lt;br&gt;
Arrows are always anonymous functions!&lt;br&gt;&lt;br&gt;

Their syntax is slightly different than function expression:
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
(args) =&gt; { statements }
&lt;/div&gt;&lt;br&gt;&lt;br&gt;

There could be few variations from this main version:&lt;br&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
(arg1, arg2, argN) =&gt; { statements }&lt;br&gt;
arg1 =&gt; { statements }&lt;br&gt;
() =&gt; { statements }&lt;br&gt;&lt;br&gt;

(arg1, arg2, argN) =&gt; { statements }&lt;br&gt;
(arg1, arg2, argN) =&gt; expression &lt;br&gt;
(arg1, arg2, argN) =&gt; ({ prop: val })&lt;br&gt;
&lt;/div&gt;&lt;br&gt;&lt;br&gt;
It means - prentheses are optional. Mostly if there is only one argument, or only one value to return, this could be simplified.&lt;br&gt;
But there is a catch:
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
(arg1, arg2, argN) =&gt; expression &lt;br&gt;
&lt;/div&gt;&lt;br&gt;
but
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
(arg1, arg2, argN) =&gt; { return expression } &lt;br&gt;
&lt;/div&gt;&lt;br&gt;&lt;br&gt;

Example:
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
(arg1, arg2) =&gt; arg1 * arg2 &lt;br&gt;&lt;br&gt;
(arg1, arg2) =&gt; { return arg1 * arg2 } &lt;br&gt;
&lt;/div&gt;&lt;br&gt;&lt;br&gt;

Both return the same, but we can write it in different way.&lt;br&gt;&lt;br&gt;</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/6504908913016889768/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2015/09/es6-arrows.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/6504908913016889768'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/6504908913016889768'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2015/09/es6-arrows.html' title='ES6 - arrows'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-8160745311598144369</id><published>2015-08-06T17:37:00.000+02:00</published><updated>2015-08-12T09:54:45.483+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="css"/><category scheme="http://www.blogger.com/atom/ns#" term="elements"/><category scheme="http://www.blogger.com/atom/ns#" term="inline"/><category scheme="http://www.blogger.com/atom/ns#" term="space"/><title type='text'>CSS - setting elements inline - part 1</title><content type='html'>I bet that every frontend developer met the problem with setting many elements in line. As lately I had to solve this problem during recruitment processes I decided to share some thoughts and solution.&lt;br&gt;&lt;br&gt;
Example structure:&lt;br&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
&amp;lt;div class=&quot;container&quot;&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;color green&quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;color yellow&quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;color blue&quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;color red&quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br&gt;
&amp;lt;/div&amp;gt;
&lt;/div&gt;&lt;br&gt;&lt;br&gt;
Let&#39;s color elements to see them clearly:&lt;br&gt;
&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
.color {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;width: 25%;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;display: inline-block;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;height: 100px;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;padding: 0;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;margin: 0;&lt;br&gt;
}
.green {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;background-color: green;&lt;br&gt;
}&lt;br&gt;
.yellow {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;background-color: yellow;&lt;br&gt;
}&lt;br&gt;
.blue {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;background-color: blue;&lt;br&gt;
}&lt;br&gt;
.red {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;background-color: red;&lt;br&gt;
}
&lt;/div&gt;&lt;br&gt;&lt;br&gt;

So we have a container, which contains few elements, and looks like on this image:&lt;br&gt;&lt;br&gt;

&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9EC05HParxLuL_Ps2_r034JoVug4Smdr_LhLbVIT_9mkgRfJnvSO_jcF2rXhT-E5i4zDQ0iQjlt_Am8KmjReeZE0cTuur8cImpgn2-8PrfVbQOhhXY4lpDIJ6EB0n75FS38Ojz557Zxye/s1600/elements_in_row_1.png&quot; imageanchor=&quot;1&quot; &gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9EC05HParxLuL_Ps2_r034JoVug4Smdr_LhLbVIT_9mkgRfJnvSO_jcF2rXhT-E5i4zDQ0iQjlt_Am8KmjReeZE0cTuur8cImpgn2-8PrfVbQOhhXY4lpDIJ6EB0n75FS38Ojz557Zxye/s320/elements_in_row_1.png&quot; /&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;

So this is definitely not the goal. The inner elements should be in line and without gaps between. Why are there those gaps? The answer is &lt;span style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;display: inline-block;&lt;/span&gt;. Displaying inline takes all white spaces as a spaces... and spaces have width, so last element is going down, as there is no space for it. So how to remove gaps between elements?&lt;br&gt;&lt;br&gt;

change boxing-size:&lt;br&gt;

&lt;div style=&quot;background-color: #cecece;font-family:courier new;font-size:85%;&quot;&gt;
div {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;boxing-size: border-box; &lt;br&gt;
}
&lt;/div&gt;&lt;br&gt;
&lt;!--
So now our page looks like:&lt;br&gt;&lt;br&gt;

&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgp1Wm7u7TIjUTiHLKPY4QIefw5rbn5hxMD4Z1Ie42GRU2O61uJGOVOpoGH47fpAOiACaQ6ekytxkI-17MO3rkCUF-M-AjU8JCfeoBEpDEANgxVa901FZR2UZmdvt1VHMegYafPO6lK_4Qh/s1600/elements_in_row_3.png&quot; imageanchor=&quot;1&quot; &gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgp1Wm7u7TIjUTiHLKPY4QIefw5rbn5hxMD4Z1Ie42GRU2O61uJGOVOpoGH47fpAOiACaQ6ekytxkI-17MO3rkCUF-M-AjU8JCfeoBEpDEANgxVa901FZR2UZmdvt1VHMegYafPO6lK_4Qh/s400/elements_in_row_3.png&quot; /&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;

Just as it should!&lt;br&gt; --&gt;</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/8160745311598144369/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2015/08/css-setting-elements-inline-part-1.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/8160745311598144369'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/8160745311598144369'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2015/08/css-setting-elements-inline-part-1.html' title='CSS - setting elements inline - part 1'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9EC05HParxLuL_Ps2_r034JoVug4Smdr_LhLbVIT_9mkgRfJnvSO_jcF2rXhT-E5i4zDQ0iQjlt_Am8KmjReeZE0cTuur8cImpgn2-8PrfVbQOhhXY4lpDIJ6EB0n75FS38Ojz557Zxye/s72-c/elements_in_row_1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-4516867317521770644</id><published>2015-08-05T12:33:00.002+02:00</published><updated>2015-08-05T16:11:33.197+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="category"/><category scheme="http://www.blogger.com/atom/ns#" term="magento"/><category scheme="http://www.blogger.com/atom/ns#" term="product"/><category scheme="http://www.blogger.com/atom/ns#" term="visible"/><title type='text'>Magento beginner - set up category and product</title><content type='html'>After installation of Magento I faced a new problem. The menu in the beginning wasn&#39;t much helpful. So I&#39;m creating short post about first steps with Magento&lt;br&gt;&lt;br&gt;

After logging in to admin area Dashbord is first visible page. If shop is live and people are buying stuff there are many useful information.&lt;br&gt;&lt;br&gt;

Before you start changing anything and ONLY if your shop is not live (online) go to System -&gt; Cache Management. Click &quot;Select All&quot;, from Action choose &quot;Disable&quot; and click &quot;Submit&quot;. This will disable cache on your Magento. So all changes should be visible immediately. If you are working on live system, remember to refresh proper cache (NOT ALL) after making changes.&lt;br&gt;&lt;br&gt;

To manage categories choose Catalog -&gt; Categories -&gt; Manage Categories. In the left column you can see already existing categories. &quot;Default category&quot; is crested by default. For your needs create new Root Category by clicking button &quot;Add Root Category&quot;. This root category would be a container for all category tree. It won&#39;t be displayed. In the first tab - &quot;General information&quot; fill name, set &quot;Is Active&quot; and &quot;Include in Navigation Menu&quot; to &quot;Yes&quot; and add all information you know would be needed. Click &quot;Save Category&quot; to save category record.&lt;br&gt;&lt;br&gt;

Then, click in the name your just created root category in the left column, to set a context, and then click button &quot;Add Subcategory&quot;. It will show you the same form. Just be sure that on &quot;General information&quot; tab you filled &quot;Name&quot; and set &quot;Is Active&quot; and &quot;Include in Navigation Menu&quot; to &quot;Yes&quot;.&lt;br&gt;&lt;br&gt;

So you should now to see our new subcategory in the menu. But if you click it it shows the page with information: &quot;There are no products matching the selection.&quot;. So let&#39;s add some products then. In admin choose Catalog -&gt; Manage Products. Click button &quot;Add Product&quot; and set product attributes (or use defaults). Click &quot;Continue&quot;. Now you can see first tab. Obligatory information are mark with asterisk. Remember to set &quot;Status&quot; to &quot;Enabled&quot;. Fill information in &quot;General&quot; and &quot;Prices&quot; tabs. Then click to &quot;Inventory&quot; tab. There set &quot;Qty&quot; to any number greater than 0 and &quot;Stock Availability&quot; to &quot;In Stock&quot;. Next click to &quot;Categories&quot; tab to bound product with category.&lt;br&gt;&lt;br&gt;

Now you have to bound your shop name with category. In admin click System -&gt; Manage Stores and for your Store Name (default is &quot;Main Website Store&quot;) choose root category you just created.&lt;br&gt;&lt;br&gt;

Still in admin click in System -&gt; Index Management and reindex whatever needs it. From now all your changes should be visible.&lt;br&gt;&lt;br&gt;</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/4516867317521770644/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2015/08/magento-beginner-set-up-category-and.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/4516867317521770644'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/4516867317521770644'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2015/08/magento-beginner-set-up-category-and.html' title='Magento beginner - set up category and product'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-7408532148492002651</id><published>2015-07-11T17:18:00.002+02:00</published><updated>2015-07-11T17:20:06.068+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="algorithms"/><category scheme="http://www.blogger.com/atom/ns#" term="codility"/><category scheme="http://www.blogger.com/atom/ns#" term="Counting Elements"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>Codility lesson 2 - JavaScript solutions</title><content type='html'>&lt;a href=&quot;https://codility.com/programmers/lessons/2&quot; target=&quot;_blank&quot;&gt;Lesson 2 - Counting Elements&lt;/a&gt; is already merged to the repo. It contains solutions for: FrogRiverOne,&lt;br&gt; PermCheck,&lt;br&gt; MissingInteger,&lt;br&gt;MaxCounters.</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/7408532148492002651/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2015/07/codility-lesson-2-javascript-solutions.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/7408532148492002651'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/7408532148492002651'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2015/07/codility-lesson-2-javascript-solutions.html' title='Codility lesson 2 - JavaScript solutions'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-646945086088680899</id><published>2015-07-06T11:40:00.000+02:00</published><updated>2015-07-06T11:40:07.614+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="algorithms"/><category scheme="http://www.blogger.com/atom/ns#" term="codility"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="time complexity"/><title type='text'>Codility Lesson 1 - JavaScript solutions</title><content type='html'>Some time ago I started to play with &lt;a href=&quot;codility.com&quot; target=&quot;_blank&quot;&gt;Codility&lt;/a&gt; challenges. As JavaScript solutions are not so popular I decided to create a &lt;a href=&quot;github.com/mayacode/codility&quot; target=&quot;_blank&quot;&gt;GitHub repository&lt;/a&gt; with my solutions.&lt;br&gt;&lt;br&gt;

&lt;a href=&quot;https://codility.com/programmers/lessons/1&quot; target=&quot;_blank&quot;&gt;Lesson 1 - Time complexity&lt;/a&gt; is already merged to the repo. It contains all three tasks: FrogJmp, PermMissingElem and TapeEquilibrium.</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/646945086088680899/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2015/07/codility-lesson-1-javascript-solutions.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/646945086088680899'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/646945086088680899'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2015/07/codility-lesson-1-javascript-solutions.html' title='Codility Lesson 1 - JavaScript solutions'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-7733065554087408930</id><published>2015-06-16T15:22:00.000+02:00</published><updated>2015-06-16T15:23:05.646+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="apply"/><category scheme="http://www.blogger.com/atom/ns#" term="array"/><category scheme="http://www.blogger.com/atom/ns#" term="frontend"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="map"/><title type='text'>Arrays in JavaScript - how to create an array and fill it with numbers</title><content type='html'>Most common way (and fastest if array would be big, please check &lt;a href=&quot;http://jsperf.com/array-magic-vs-for&quot; target=&quot;_blank&quot;&gt;jsperf.com/array-magic-vs-for&lt;/a&gt;):&lt;br&gt;
&lt;div style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;
var arr = [];&lt;br&gt;
var max = 100;&lt;br&gt;
for (var i = 0; i &lt; max; i++) {&lt;br&gt;
&amp;nbsp;&amp;nbsp;arr.push(i);&lt;br&gt;
}
&lt;/div&gt;&lt;br&gt;

But if array wouldn&#39;t be so big, we can use:&lt;br&gt;
&lt;div style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;
var max = 7;&lt;br&gt;
var arr = Array.apply(null, {length: max}).map(Number.call, Number);&lt;br&gt;
&lt;/div&gt;&lt;br&gt;

Of course very often we need some specific values. Fortunately &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;map()&lt;/span&gt; gives us many options:&lt;br&gt;
&lt;div style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;
var max = 9;&lt;br&gt;
var arr1 = Array.&lt;br&gt;
&amp;nbsp;&amp;nbsp; apply(null, {length: max}).&lt;br&gt;
&amp;nbsp;&amp;nbsp; map(function(item, index){ return ++index;});&lt;br&gt;
var arr2 = Array.&lt;br&gt;
&amp;nbsp;&amp;nbsp; apply(null, {length: max}).&lt;br&gt;
&amp;nbsp;&amp;nbsp; map(Function.call, Math.random);&lt;br&gt;
&lt;/div&gt;&lt;br&gt;</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/7733065554087408930/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2015/06/arrays-in-javascript-how-to-create.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/7733065554087408930'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/7733065554087408930'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2015/06/arrays-in-javascript-how-to-create.html' title='Arrays in JavaScript - how to create an array and fill it with numbers'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-4648124563438430064</id><published>2014-11-28T14:52:00.000+01:00</published><updated>2014-11-28T14:54:31.572+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="cookie"/><category scheme="http://www.blogger.com/atom/ns#" term="document.cookie"/><category scheme="http://www.blogger.com/atom/ns#" term="Explorer"/><category scheme="http://www.blogger.com/atom/ns#" term="frontend"/><category scheme="http://www.blogger.com/atom/ns#" term="IE"/><category scheme="http://www.blogger.com/atom/ns#" term="Internet"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="opera"/><category scheme="http://www.blogger.com/atom/ns#" term="path"/><category scheme="http://www.blogger.com/atom/ns#" term="ścieżka"/><title type='text'>gdzie jest moje ciasteczko??</title><content type='html'>Czasami nie da sie inaczej i trzeba sięgnąć po cookie. Tak właśnie było tym razem. Prosta sprawa, user wchodzi na nasz portal, to zapamiętujemy w cookie stronę od której zaczął przeglądanie naszej witryny. Napisałam sobie prosty kod, bez żadnych bibliotek (takie coś na start, żeby mieć kod do refaktoringu i testowania rozwiązania). Pod Chrome i FF działa jak złoto, pod natywną Androidową przeglądarką również.&lt;br&gt;&lt;br&gt;

Pokazałam rozwiazanie naszemu seniorowi. Rzucił oczkiem i podpowiedział kilka usprawnień, m.in. wykorzystanie ścieżki ze zmiennej globalnej a nie wpisywanie jej z palca (biorąc pod uwagę fakt, że to było tylko dla jednego adresu, to co różnica?). Poprawiłam, przetetsowałam. Działa.&lt;br&gt;&lt;br&gt;

Jako, że rozwiązanie ogólnie przeznaczone jest tylko pod przegladarki mobilne, nie przykładałam specjalnej wagi do testowania na desktopowych. Sprawdziłam na wszystkich przeglądarkach zainstalowanych na moim HTC M8 - natywna, Chrome i FF. Działa jak złoto. Chciałam sprawdzaić pod Operą mini, ale złosliwa małpa nie chciała się łączyć z serwerem dev. Poszłam po inny telefon, to działu mobilnego. Tam na jakimś Samsungu postawili mi Operę mini, która też odmówiła współpracy. Olałam sprawę i wzięłam się za testowanie pod zwykłą Operą.&lt;br&gt;&lt;br&gt;

No i nie działa :(. Błędem nie rzuca, ale i nie działa. No pięknie... Jeszcze koleżanka, z którą robiłam pair programming sprawdziła na swoim WindowsPhone pod IE i też nie działa. No ki diabeł? Zostawiłam jak jest. Następnego dnia rano usiadłam do debuggowania. Modern.IE stoi na Virtualboxie, wiec wzięłam IE10 na tapetę i zaczynam debuggować. Linijka po linijce... i co? I jajo... cookie sie nie zapisuje. No jak to się nie zapisuje? - prowadzę monolog w duszy debuggując dalej. Krok po kroku testując różne ustawienia doszłam dlaczego to cookie się nie zapisuje...&lt;br&gt;&lt;br&gt;

Składnia jest banalnie prosta: &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;document.cookie(&quot;nazwa=wartość&quot;);&lt;/span&gt;. Można ją rozszerzyć o datę ważności cookie: &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;document.cookie(&quot;nazwa=wartość; expire=data&quot;)&lt;/span&gt; albo o ścieżkę dla której cookie jest ważne: &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;document.cookie(&quot;nazwa=wartość; expire=data; path=ścieżka&quot;)&lt;/span&gt;. I to właśnie ta ścieżka była przyczyną problemów dla Opery i IE. Używałam ścieżki pełnej, branej ze zmiennej globalnej: &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;http://server-name.domain.com/costam/&lt;/span&gt; co okazało się zupełnie niestrawne dla tych dwóch przeglądarek. Obie wymagają podania ścieżki zaczynając od &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;/&lt;/span&gt;, czyli bez domeny.&lt;br&gt;&lt;br&gt;

Oczywiście jaśnie oświecona Opera, ani tym bardziej IE nie dały nawet pół błędu, nic. Po prostu nie zapisywały cookie...&lt;br&gt;&lt;br&gt;</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/4648124563438430064/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2014/11/gdzie-jest-moje-ciasteczko.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/4648124563438430064'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/4648124563438430064'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2014/11/gdzie-jest-moje-ciasteczko.html' title='gdzie jest moje ciasteczko??'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-4694408567543163615</id><published>2014-02-10T14:37:00.001+01:00</published><updated>2014-02-10T14:37:39.102+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="css"/><category scheme="http://www.blogger.com/atom/ns#" term="flex"/><category scheme="http://www.blogger.com/atom/ns#" term="flexbox"/><category scheme="http://www.blogger.com/atom/ns#" term="flexible box layout module"/><category scheme="http://www.blogger.com/atom/ns#" term="frontend"/><category scheme="http://www.blogger.com/atom/ns#" term="links"/><title type='text'>CSS Flexible box layout module - part 7 - Conclusions and links</title><content type='html'>&lt;b&gt;Conclusions&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;

CSS flexible box layout module is an amazing tool to make web pages flexible without any calculations. It makes our containers just fit to the available space and act as we want them on different screen sizes. It will take some time as browser vendors will implement all features and we could use it without vendor prefixes. But it is worthy to wait and read about flexbox, to find callbacks for older browsers to make it ready to use as fast as possible.&lt;br /&gt;&lt;br /&gt;

&lt;b&gt;Links&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;

It doesn&#39;t make any sense to copy information from some useful sites. Please check this links and enjoy all opportunities flexbox provides!&lt;br /&gt;&lt;br /&gt;

&lt;a href=&quot;http://www.w3.org/TR/css3-flexbox/&quot; target=&quot;_blank&quot;&gt;http://www.w3.org/TR/css3-flexbox/&lt;/a&gt; (official specification)&lt;br /&gt;&lt;br /&gt;

&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes&quot; target=&quot;_blank&quot;&gt;https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;

&lt;a href=&quot;http://umaar.github.io/css-flexbox-demo/&quot; target=&quot;_blank&quot;&gt;http://umaar.github.io/css-flexbox-demo/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;

&lt;a href=&quot;http://caniuse.com/flexbox&quot; target=&quot;_blank&quot;&gt;http://caniuse.com/flexbox&lt;/a&gt; (which browsers support flexbox)&lt;br /&gt;&lt;br /&gt;

&lt;a href=&quot;http://css-tricks.com/using-flexbox/&quot; target=&quot;_blank&quot;&gt;http://css-tricks.com/using-flexbox/&lt;/a&gt; (vendor prefixes tables)&lt;br /&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/4694408567543163615/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2014/02/css-flexible-box-layout-module-part-7.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/4694408567543163615'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/4694408567543163615'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2014/02/css-flexible-box-layout-module-part-7.html' title='CSS Flexible box layout module - part 7 - Conclusions and links'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-1936838816718846697</id><published>2014-02-10T14:34:00.001+01:00</published><updated>2014-02-10T14:34:33.674+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="css"/><category scheme="http://www.blogger.com/atom/ns#" term="flex"/><category scheme="http://www.blogger.com/atom/ns#" term="flexbox"/><category scheme="http://www.blogger.com/atom/ns#" term="flexible box layout module"/><category scheme="http://www.blogger.com/atom/ns#" term="frontend"/><category scheme="http://www.blogger.com/atom/ns#" term="wrap"/><title type='text'>CSS Flexible box layout module - part 6 - Setting elements in more than one line</title><content type='html'>Not known amount of flex items not always can be solved with flex-grow property. Sometimes there are too many items to get fit on one line. Then we can put them in many lines using &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flow-wrap&lt;/span&gt; property on flex container.&lt;br /&gt;&lt;br /&gt;

&lt;div style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;
flow-wrap: nowrap; &lt;i style=&quot;color: #989898&quot;&gt;/* forces flex container to display all flex items in one line */&lt;/i&gt;&lt;br /&gt;
flow-wrap: wrap; &lt;i style=&quot;color: #989898&quot;&gt;/* allows flex container to display flex items in multiple lines, direction is defined by &lt;b&gt;flex-direction&lt;/b&gt; */&lt;/i&gt;&lt;br /&gt;
flow-wrap: wrap-reverse; &lt;i style=&quot;color: #989898&quot;&gt;/* the same as “&lt;b&gt;wrap&lt;/b&gt;”, opposite to direction defined by &lt;b&gt;flex-direction&lt;/b&gt; */&lt;/i&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;

So if we have style definitions like:&lt;br /&gt;&lt;br /&gt;

&lt;div style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;
section {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;border: 1px solid #000000;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;display: flex;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;flex-wrap: wrap;&lt;br /&gt;
}&lt;br /&gt;&lt;br /&gt;

div {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;background-color: #C0C0C0;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;margin: 7px;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;flex-grow: 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;

The result will change, depending on browser window width:&lt;br /&gt;&lt;br /&gt;

1. For section has a 760px of width:&lt;br /&gt;&lt;br /&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg429zzcpwZ2sI1R6uopsZzy-rIOdMolH60jKFIkOspfzCfKz-4wif0oXdXmVTcriLNonInmtcn7T40IjKK-2jBcPBT4UopL8TQ8PYpCsZ1tnQfROnfXGjiCfGq2r6vPRKdIl-bwRUdECVO/s1600/wrap.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg429zzcpwZ2sI1R6uopsZzy-rIOdMolH60jKFIkOspfzCfKz-4wif0oXdXmVTcriLNonInmtcn7T40IjKK-2jBcPBT4UopL8TQ8PYpCsZ1tnQfROnfXGjiCfGq2r6vPRKdIl-bwRUdECVO/s400/wrap.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;

2. section has a 480px of a width:&lt;br /&gt;&lt;br /&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRAsZjWpA8sOba5qvILopVK2rqmJ-crjcncNlj3gg26I8mvbkDog-ud2RY4ZasKfiQ1ll0Hm_x3Cy9s9zXQ27WpMhhwMS6X8jCOBYnqz4dDGg77sJbZqR0fKtWgC33vs12BkfnXLnckR51/s1600/wrap2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRAsZjWpA8sOba5qvILopVK2rqmJ-crjcncNlj3gg26I8mvbkDog-ud2RY4ZasKfiQ1ll0Hm_x3Cy9s9zXQ27WpMhhwMS6X8jCOBYnqz4dDGg77sJbZqR0fKtWgC33vs12BkfnXLnckR51/s400/wrap2.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;



</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/1936838816718846697/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2014/02/css-flexible-box-layout-module-part-6.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/1936838816718846697'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/1936838816718846697'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2014/02/css-flexible-box-layout-module-part-6.html' title='CSS Flexible box layout module - part 6 - Setting elements in more than one line'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg429zzcpwZ2sI1R6uopsZzy-rIOdMolH60jKFIkOspfzCfKz-4wif0oXdXmVTcriLNonInmtcn7T40IjKK-2jBcPBT4UopL8TQ8PYpCsZ1tnQfROnfXGjiCfGq2r6vPRKdIl-bwRUdECVO/s72-c/wrap.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-1219953639261967028</id><published>2014-02-10T14:10:00.002+01:00</published><updated>2014-02-10T14:11:05.701+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="css"/><category scheme="http://www.blogger.com/atom/ns#" term="flex"/><category scheme="http://www.blogger.com/atom/ns#" term="flexbox"/><category scheme="http://www.blogger.com/atom/ns#" term="flexible box layout module"/><category scheme="http://www.blogger.com/atom/ns#" term="frontend"/><category scheme="http://www.blogger.com/atom/ns#" term="order"/><category scheme="http://www.blogger.com/atom/ns#" term="ordinal group"/><title type='text'>CSS Flexible box layout module - part 5 - Changing order of elements</title><content type='html'>On interactive pages it is common that DOM elements move, disappear or appear as a result of user&#39;s behavior. CSS3 provides very useful property &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;order&lt;/span&gt;, to ordering elements inside flex container. By default all flex items belong to one ordinal group – 0. If we want to change place of specific flex item, easiest way is to change its ordinal group number. Value of this property is an integer and represents the ordinal group the flex item has been assigned. Items are ordered by ascending ordinal group number.&lt;br /&gt;&lt;br /&gt;

So if we have 6 flex items inside flex container and define &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;order: 1;&lt;/span&gt; for the first one, than it will be displayed in the end of flex container. Elements that belong to the same ordinal group are displaying in the order from HTML.</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/1219953639261967028/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2014/02/css-flexible-box-layout-module-part-5.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/1219953639261967028'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/1219953639261967028'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2014/02/css-flexible-box-layout-module-part-5.html' title='CSS Flexible box layout module - part 5 - Changing order of elements'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-6956773274869300698</id><published>2014-02-10T14:04:00.001+01:00</published><updated>2014-02-10T14:05:58.614+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="basis"/><category scheme="http://www.blogger.com/atom/ns#" term="css"/><category scheme="http://www.blogger.com/atom/ns#" term="flex"/><category scheme="http://www.blogger.com/atom/ns#" term="flexbox"/><category scheme="http://www.blogger.com/atom/ns#" term="flexible box layout module"/><category scheme="http://www.blogger.com/atom/ns#" term="frontend"/><category scheme="http://www.blogger.com/atom/ns#" term="grow"/><category scheme="http://www.blogger.com/atom/ns#" term="shrink"/><title type='text'>CSS Flexible box layout module - part 4 - Altering flex items dimensions to fill the available space</title><content type='html'>We have a flex container and inside we have not known amount of flex items, and we want them to fill available space. For this we have to use &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-grow&lt;/span&gt; property on flex items.&lt;br /&gt;&lt;br /&gt;

&lt;div style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-grow: x;&lt;/div&gt;&lt;br /&gt;

How &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-grow&lt;/span&gt; property works? Browser sums values of &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-grow&lt;/span&gt; property in flex items and then alter flex items width to be equal x/sum of all available space. For example, if we have 3 flex items, and every has &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-grow: 1;&lt;/span&gt;, it means that every flex element takes 1/3 of available space.&lt;br /&gt;&lt;br /&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBJjvYNfrkMORpXFHfni5jVg_XQohRcuaQi09Aa34_2a-imYtDHwdVwaQONzLlklCM9FAMk148lWsxLs52Hw38mMia7DTg3xxmOc4R8IztPP4zv7X528spQQFGxqQWgQHvr-ri5f0u20hU/s1600/flex-grow.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBJjvYNfrkMORpXFHfni5jVg_XQohRcuaQi09Aa34_2a-imYtDHwdVwaQONzLlklCM9FAMk148lWsxLs52Hw38mMia7DTg3xxmOc4R8IztPP4zv7X528spQQFGxqQWgQHvr-ri5f0u20hU/s400/flex-grow.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;

This is an example, where first flex item has &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-grow: 1;&lt;/span&gt; second one has &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-grow:3&lt;/span&gt; and last one has &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-grow: 2;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;

But there is more properties related to filling available space. We can define &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-shrink&lt;/span&gt; property with number as a value and &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-basis&lt;/span&gt; with a proper width as a value.&lt;br /&gt;&lt;br /&gt;

&lt;div style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;
flex-shrink: x;&lt;br /&gt;
flex-basis: Xpx;
&lt;/div&gt;&lt;br /&gt;

&lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-basis&lt;/span&gt; defines the ideal width of flex item, together with &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-grow&lt;/span&gt; define how flex items should look like on different screens. If &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-basis&lt;/span&gt; is defined &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-grow&lt;/span&gt; define which part of available space will take flex item.&lt;br /&gt;&lt;br /&gt;

&lt;span style=&quot;text-decoration: underline&quot;&gt;Example 1.1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;

We have 499px width flex container with 2 flex items (A and B). Both flex items have 200px width, but A has &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-grow: 1;&lt;/span&gt; and B has &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-grow: 2;&lt;/span&gt;. So we have 400px reserved for width of both flex items and 99px of extra available space. It means that all available space we have – 99px – we need to divide on 3 parts (because we sum flex-grow of both elements, 1 + 2 = 3) and element A gets 1/3 * 99 = 33px and B: 2/3 * 99 = 66px. So in browser we will see element A width 233px and element B width 266px;.&lt;br /&gt;&lt;br /&gt;

&lt;span style=&quot;text-decoration: underline&quot;&gt;Example 1.2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;

But what happens if there is no available space? If there is no available space flex-grow is not used. Assuming, both items (A and B) have the same value of &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-basis: 200px;&lt;/span&gt;, and flex container has &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;width: 300px;&lt;/span&gt;. There is no space for two flex items, so their widths will be recalculated based on given &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-basis&lt;/span&gt;. Our flex items are the same, so every will take ½ of flex container width.&lt;br /&gt;&lt;br /&gt;

&lt;span style=&quot;text-decoration: underline&quot;&gt;Example 1.3&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;

But what if we have flex items with different value of &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-basis&lt;/span&gt; property? For example A has 200px and B 150px. Flex container still has 300px of width. Both flex items need to be squeezed to fit the available spaces. Browser gets a factor dividing available space (300px) on counted from flex items flex-basis properties (350px). Then uses this factor (~0.85) to calculate new widths of flex items. Flex item A will have 171px and B will have 129px.&lt;br /&gt;&lt;br /&gt;

&lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-shrink&lt;/span&gt; defines, how flex item shrinks, if there is no available space, in comparison to other flex items in flex container.&lt;br /&gt;&lt;br /&gt;

&lt;span style=&quot;text-decoration: underline&quot;&gt;Example 1.4&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;

Assuming, we have flex container 300px width and inside are 2 flex items (A and B), and every has &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-basis&lt;/span&gt; equal 200px. Item A has &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-shrink: 1;&lt;/span&gt; and B has &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-shrink: 2;&lt;/span&gt;. Here it is a little more complicated. First browser calculates how much more space is needed (400px-300px=100px), then divides it on sum flex-shrink values of all flex items (100/3 = 33.3). Then calculates what amount should subtract from given flex-basis value using flex-shrink. For flex item A it will be 33.3x1 (&lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-shrink: 1;&lt;/span&gt;), so item A will have 167px of width. Flex item B will have 133px, (200px – (33.3px x2)).&lt;br /&gt;&lt;br /&gt;

&lt;span style=&quot;text-decoration: underline&quot;&gt;Example 1.5&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;

Let&#39;s mix examples and take hardest version. So we have flex container 300px width. Inside it contains 2 flex items (A and B). Item A has &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-basis: 200px;&lt;/span&gt; and &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-shrink: 1;&lt;/span&gt; item B has &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-basis: 150px;&lt;/span&gt; and &lt;span style=&quot;background-color: #dedede;font-family:courier new;font-size:12px&quot;&gt;flex-shrink: 2;&lt;/span&gt;. So what is a result? Item A is 180px width and item B 120px. Why? Because item B shrinks more than item A. In this case, item A was squeezed by 10% and item B by 20%, 2 times more, just as flex-shrink property was set.

</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/6956773274869300698/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2014/02/css-flexible-box-layout-module-part-4.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/6956773274869300698'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/6956773274869300698'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2014/02/css-flexible-box-layout-module-part-4.html' title='CSS Flexible box layout module - part 4 - Altering flex items dimensions to fill the available space'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBJjvYNfrkMORpXFHfni5jVg_XQohRcuaQi09Aa34_2a-imYtDHwdVwaQONzLlklCM9FAMk148lWsxLs52Hw38mMia7DTg3xxmOc4R8IztPP4zv7X528spQQFGxqQWgQHvr-ri5f0u20hU/s72-c/flex-grow.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3386683896821079506.post-8272619978667376871</id><published>2013-10-07T16:32:00.000+02:00</published><updated>2013-10-07T16:33:43.771+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="dzieci"/><category scheme="http://www.blogger.com/atom/ns#" term="przemyślenia"/><category scheme="http://www.blogger.com/atom/ns#" term="rodzina"/><category scheme="http://www.blogger.com/atom/ns#" term="szkola"/><category scheme="http://www.blogger.com/atom/ns#" term="tornister"/><title type='text'>szkola, tornister i dziecko</title><content type='html'>Tak ostatnio widze, ze znow media sie obudzily, ze tornistry ciezkie. Ja pamietam swoj tornister jako mega ciezki, zwlaszcza w liceum, gdzie objetosc ksiazek byla calkiem spora, przez co waga tez niczego sobie. Do tego atlasy, zeszyty, czesto zbiory zadan itp. Majac 7-8 roznych przedmiotow w ciagu dnia - tornister pekal w szwach. Koszty tez nie male.&lt;br /&gt;&lt;br /&gt;

Koszty ksiazek do obecnej pierwszej klasy technikum to wydatek rzedu 500 pln, do tego lista potrzebnych narzedzi na praktyki (klasa o profilu fryzjerskim) kolejne 500 pln. koszt takiej wyprawki - 1k pln. Masakra.&lt;br /&gt;&lt;br /&gt;

Moja najmlodsza corka wlasnie rozpoczela przygode ze szkola (w Niemczech, gdzie mieszkamy). Koszt wyprawki (podreczniki, cwiczenia i zeszyty) na nastepne 2 lata - 90 euro. Koszt wszystkich potrzebnych dodatkowych pomocy (tez na 2 lata) - czyli plastelina, rozne rodzaje kredek, bloki roznej wielkosci, olowki, dlugopisy, papier kolorowy, jakies folie i naklejki - 60 euro. W sumie 150 euro, ktore zaplacilismy naszej nauczycielce, bo to ona zajmuje sie zakupem podrecznikow (w ilosci wiekszej niz ilosc dzieci w klasie, bo wiadomo, dzieci gubia niszcza itp). Dodam, ze limit wynosi 100 euro/dziecko/rok - limit ten dotyczy kwoty, jaka rodzice wydaja na ksiazki dla swoich pociech.&lt;br /&gt;&lt;br /&gt;

Jak to wyglada w praktyce? W pierwszej klasie dzieci maja zadawane niewiele o ile w ogole. Ksiazki sa przeznaczone na mniej wiecej 2-3 miesiace uzywania, wiec sa cieniutkie, maja miekkie okladki. WSZYSTKIE ksiazki i zeszyty zostaja w szkole. Jesli dziecko nie odrobi lekcji w swietlicy, to bierze potrzebne materialy do domu, jesli odrobi ksiazka/zeszyt/cwiczenia z odrobiona praca domowa trafia w odpowiednie miejsce w sali lekcyjnej.&lt;br /&gt;&lt;br /&gt;

Tak na prawde ja niewiele wiem o tym, jak i czego uczy sie moje dziecko. Moge tylko powiedziec, ze przed rozpoczeciem roku szkolnego (co nastapilo 10 sierpnia) Mala umiala czytac powoli i sylabizujac po polsku. Miala problem z niemieckimi regulami, wiec niechetnie probowala czytac niemieckie teksty, mimo, ze mowi plynnie po niemiecku. Na chwile obecna (po 2 miesiacach nauki) pisze i czyta po niemiecku. Wciaz miesza litery (male i duze), ale na tym etapie nacisk jest kladziony na umiejetnosc napisania i przeczytania, styl nie jest wazny, zasady ortograficzne tez nie. Wazne, ze dziecko moze sie komunikowac w formie pisemnej.&lt;br /&gt;&lt;br /&gt;

Dzieciaki maja taki specjalny zeszyt, gdzie rysuja np co robili w weekend, albo wyrazaja na ryskunku, czy im sie podobala ksiazka, w ktorej ostatnio pracowali. Dzieci chetnie dodaja opisy do swoich tekstow. Nauczycielka ma ich 23 w klasie i sprawdza kazda taka prace z osobna, pisze swoje komentarze (pieknymi wyraznymi, pisanymi literkami, ktorych zazdroszcza jej wszystkie dzieci). Czasami poprawia pisownie, ale nie kreslac tekstow dziecka, ale dodajac swoj komentarz i proszac by dziecko napisalo to samo obok, ale juz poprawnie.&lt;br /&gt;&lt;br /&gt;

A wracajac do tornistra. Mloda ma wielki, wypasiony i wymarzony tornister. Wazy on cos kolo 2-3kg. Razem z zawartoscia (piornik, teczka i zeszyt do komunikacji z nauczycielami, kanapki i butla z woda) jakies 4kg. Mloda musi go wniesc na 2 pietro po schodach (ma klase na 2 pietrze), po lekcjach musi go przeniesc do swietlicy (na tym samym pietrze, moze 15 metrow od klasy), jesli odbieram ja po 16:30 to musi go zniesc na parter do drugiej sali. Zaprowadzajac ja do szkoly lub odbierajac zawsze sama niose plecak. Stanowczy plus z lekcji w jednej sali.&lt;br /&gt;&lt;br /&gt;

Starsze dzieci tez maja ksiazki w szkole. Szkola sama sponsoruje ksiazki, ktore nie mieszcza sie w ustawowych 100 euro (czyli zasadnicza wiekszosc). W praktyce jest kilka sztuk w bibliotece i nauczyciele kseruja odpowiednie rozdzialy. Do kazdego przedmiotu jest miekki segregator, do ktorego wpina sie xerowki + kartki do notatek. Po zakonczeniu dzialu xerowki i zapisane kartki zostawia sie w domu, a do szkoly nosi sie pusty segregator przygotowany na nowe xerowki. W ten spsob plecaki sa lekkie.&lt;br /&gt;&lt;br /&gt;

Uwazam to za bardzo dobre rozwiazania. Podoba mi sie wersja z kilkoma cienkimi ksiazkami na rok, bo jesli nawet trzeba cos odrobic w domu, to ciezar takiej ksiazki jest niewielki. Podobaja mi sie lekcje w jednym miejscu (wyjatkiem jest religia i gimnastyka, ale i tak dzieci zostawiaja tornistry w swojej klasie). Podoba mi sie pomysl z xerowaniem potrzebnych materialow i noszeniem do szkoly tego, co jest w chwili obecnej potrzebne, a nie calej wielkiej ksiazki do tego oprawionej w twarda okladke. Podoba mi sie system zapewniajacy miejsce do odrabiania lekcji i fachowa opieke w swietlicy. Dodam, ze panie pracujace w swietlicy sa oplacane przez miasto, a nie przez szkole. Podoba mi sie praca z uczniem w szkole, gdzie odrabianie prac domowych jest sporadyczne i sluzy glownie pochwaleniu sie rodzicom co dziecko juz umie.</content><link rel='replies' type='application/atom+xml' href='http://kobietawit.blogspot.com/feeds/8272619978667376871/comments/default' title='Komentarze do posta'/><link rel='replies' type='text/html' href='http://kobietawit.blogspot.com/2013/10/szkola-tornister-i-dziecko.html#comment-form' title='Komentarze (0)'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/8272619978667376871'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3386683896821079506/posts/default/8272619978667376871'/><link rel='alternate' type='text/html' href='http://kobietawit.blogspot.com/2013/10/szkola-tornister-i-dziecko.html' title='szkola, tornister i dziecko'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>