-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
150 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
--- | ||
posttype: 'blog' | ||
title: 'JavaScript Arrow Functions' | ||
date: 2020-11-01 12:00:00 | ||
author: 'Shafiqul Islam Shuvo' | ||
image: '../../images/javascript-arrow-function.jpg' | ||
postdescription: "Arrow Functions in JavaScript" | ||
tags: | ||
- JavaScript | ||
- ES6 | ||
--- | ||
|
||
**Arrow** function was introduced with **ES6** as a new syntax for writing JavaScript functions. There are a few differences between **arrow** functions and **regular** functions | ||
|
||
<h5 class="post-subheading">Arrow Function <em>vs</em> Regular Function</h5> | ||
|
||
<table class="table table-bordered"> | ||
<thead class="thead-light"> | ||
<tr> | ||
<th class="text-center">Arrow Function</th> | ||
<th class="text-center">Regular Function</th> | ||
</tr> | ||
</thead> | ||
<tr> | ||
<td width="50%">The value of <code>this</code> will always be inherited from the outer function. If there is no outer function, <code>this</code> will refer to the global object. In other words, the arrow function resolves <code>this</code> lexically.</td> | ||
<td>The value of <code>this</code> depends how the function is invoked or who owns the function: | ||
<ul class="point-list"> | ||
<li>1. Simple invocation - <code>this</code> refers to the global object</li> | ||
<li>2. Method invocation – <code>this</code> refers to the parent object</li> | ||
<li>3. Constructor invocation – <code>this</code> refers to the newly created instance</li> | ||
</ul> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td>Doesn’t have <code>arguments</code> object but we can access the arguments using a rest parameter <code>…args</code></td> | ||
<td>Has a special <code>arguments</code> object containing the list of arguments</td> | ||
</tr> | ||
<tr> | ||
<td>Supports implicit <code>return</code> expression statement.</td> | ||
<td><code>return</code> expression statement needs to be explicitly declared.</td> | ||
</tr> | ||
<tr> | ||
<td>A <strong>class method</strong> defined as arrow function will always bind <code>this</code> to the class instance.</td> | ||
<td>If a <strong>class method</strong> defined as a regular function and used as a <strong>callback</strong>, we have to bind <code>this</code> to the method.</td> | ||
</tr> | ||
</table> | ||
|
||
<br> | ||
<h5 class="post-subheading">Arrow Functions should be used when</h5> | ||
|
||
<ul class="point-list"> | ||
<li>The value of <code>this</code> needs to be consistent and returns the same value always</li> | ||
<li>The function has only one line of statement and which may be a simple <code>return expression</code></li> | ||
<li>The function doesn't need to access its <code>arguments</code> object</li> | ||
<li><strong>Callback</strong> functions with static context</li> | ||
</ul> | ||
|
||
<h5 class="post-subheading">Arrow Functions shouldn't be used when</h5> | ||
|
||
<ul class="point-list"> | ||
<li>As an object property or object prototype (<code>this</code> inside the arrow function will refer to "window" object instead of the parent object/function)</li> | ||
<li><strong>Callback</strong> functions with dynamic context</li> | ||
<li>The function will be used as a <code>constructor</code></li> | ||
<li>The <code>return expression</code> statement needs to be explicit</li> | ||
<li>Need to access the <code>arguments</code> object of the function</li> | ||
</ul> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
posttype: 'blog' | ||
title: 'CSS BEM Methodology' | ||
date: 2020-11-11 12:00:00 | ||
author: 'Shafiqul Islam Shuvo' | ||
image: '../../images/css-bem-methodology.png' | ||
postdescription: "BEM Methodology is a popular naming convention for classes in HTML and CSS" | ||
tags: | ||
- CSS | ||
- BEM | ||
--- | ||
|
||
The **BEM** methodology (Block, Element, Modifier) is a popular naming convention for classes in HTML and CSS. | ||
|
||
|
||
|
||
It is less confusing comparing to the other methods (i.e. **SMACSS**) but still provides a good architecture with a recognizable terminology. | ||
|
||
<br> | ||
|
||
<h5 class="post-subheading">3 principle elements of BEM</h5> | ||
|
||
<ul class="point-list mb-1"> | ||
<li><strong>Block</strong>: Container, Wrapper, Layout elements</li> | ||
</ul> | ||
|
||
**Example:** `.form`, `.menu` | ||
|
||
<ul class="point-list mb-1"> | ||
<li><strong>Element</strong>: Child of a Block element</li> | ||
</ul> | ||
|
||
**Example:** `.form__input`, `.menu__item` | ||
|
||
<ul class="point-list mb-1"> | ||
<li><strong>Modifier</strong>: can change the appearance of a Block or Element</li> | ||
</ul> | ||
|
||
**Example:** `.form__input--disabled`, `.menu__item--active` | ||
|
||
<br> | ||
|
||
<h5 class="post-subheading">Rules of BEM</h5> | ||
|
||
<ul class="point-list"> | ||
<li>HTML <strong>tag</strong> or <strong>ID</strong> selector shouldn't be used</li> | ||
<li><strong>Elements</strong> are namespaced using the <strong>Block</strong> names and separated by <code>__</code> (double underscores)</li> | ||
<li><strong>Modifiers</strong> are separated by <code>—-</code> (double hyphens)</li> | ||
</ul> | ||
|
||
<br> | ||
|
||
<h5 class="post-subheading">Benefits of using BEM</h5> | ||
|
||
<ul class="check-list"> | ||
<li><strong>BEM</strong> is hugely adopted and one of the most popular methodology for writing CSS</li> | ||
<li><strong>BEM</strong> helps to build a solid structure that remains simple and easy to understand.</li> | ||
<li>Because of strict naming conventions, there is less possibility to run into conflicts with CSS names</li> | ||
<li>Everything is a <strong>class</strong> and nothing is nested, so won't have to face <strong>specificity</strong> related issues.</li> | ||
<li>The Prolonged naming convention can reduce the readability of the code but it helps to understand the role of each element.</li> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters