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
/** | |
* Custom Column control | |
* Reference: https://github.com/WordPress/gutenberg/blob/master/packages/block-library/src/columns/index.js | |
*/ | |
import { times } from 'lodash'; | |
import classnames from 'classnames' | |
import memoize from 'memize'; | |
/** |
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
/** | |
The following example is a simple use case of Object.keys and Array.map functions | |
to loop through a nested JavScript array with object nested into it. | |
Steps: | |
1. Used a map() method on the main array, i.e. examResult | |
2. Started looping through the mapped object | |
3. If the loop encounters a JavaScript Object (marks in this case) it applied Object.keys method on it | |
Structure of examResult array: |
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
/** | |
Declaring Person class, its constructor and methods. | |
This class will be inherited by GetPerson class later to access its properties and methods. | |
*/ | |
class Person { | |
constructor(person) { | |
this.name = person.name; | |
this.jobTitle = person.jobTitle; |
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
/** | |
Example 1 | |
The object called 'person' has three properties (location being a nested object) | |
and one method definition. The method showDetail prints values of different properties | |
of the same object where the function is defined. | |
*/ | |
var person = { | |
fullName: 'Subrata Sarkar', | |
jobTitle: 'Web developer', | |
location: { |
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
/** | |
ES6 has provided us two very powerful methods - Rest Parameters and Spread Operators. | |
In this example I have tried to explain these methods, how they work and what we can get out of them. | |
Rest Parameter and Spread Operator have made code clean and easier to understand. | |
With these methods, the development time has decreased considerably as well. | |
Before going into code example, some key points which I want to mention. | |
1. Both Rest Parameter and Spread Operator use the sanme ‘...’ syntax. |
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
/** | |
The following code snippet shows how to use named parameters | |
by using the help of Object Destructuring. | |
Function emiCalculator() takes one argument whcih is a destructured object with | |
multiple entries, of which two have default values set (in ES6 we can set default values for parameters) | |
When calling the function we would pass three values i.e. rawPrice and downPayment and emiCount (although it has a | |
default value set) and won't pass any value for 'interestPerAnum'. | |
For destructured parameters we have pass their values like { parameterName: {properyName: value} } |
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
/** | |
A simple example showing how Multiple return values are handled in ES6 and then further modified it using Object Destructuring. | |
I have used ES6 function syntax and ES6 template literal approach in this example. | |
*/ | |
// Function to return multiple values (properties) bundled inside a JavaScript object. | |
const compoundInterestCalculator = ( amount, roi, compoundingTimesPeryear, years ) => { | |
const maturityAmount = (amount * Math.pow((1 + (roi/(compoundingTimesPeryear*100))), (compoundingTimesPeryear*years))); | |
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
//Declare a JavaScript complex object | |
const user = { | |
name: 'Subrata Sarkar', | |
age: 47, | |
gender: 'Male', | |
location: { | |
address: { | |
aptno: 'D3', | |
bldg: 'City Heights - Phase 9', |
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
/** | |
A simple example of default parameter handling inside a JavaScript class which uses a constructor | |
*/ | |
class paramValueExample { | |
constructor(x, y) { | |
this.x = 25; | |
this.y = 50; | |
this.fruits = ['banana', 'apple', 'grapes']; | |
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
// Default parameter syntax in ES6 | |
// Until ES5 we were not able to declare a default value to function paramters | |
// ES6 gives us the liberty to do that | |
// Parameters value type has no restriction, it could either be an Integer or a String or an Array or even a JavaScript object | |
// ************************************************* | |
// THE ES5 WAY: Let's see how we use to do it in ES5 | |
// *************************************************/ | |
var objAboutPerson = { |
NewerOlder