Skip to content

Instantly share code, notes, and snippets.

View sanketmeghani's full-sized avatar

Sanket Meghani sanketmeghani

View GitHub Profile
@sanketmeghani
sanketmeghani / event-handlers-with-parameters-property-initializer.js
Created August 11, 2017 15:57
React event handler with parameters using property initializer syntax
handleClick = (param) => (e) => {
console.log('Event', e);
console.log('Parameter', param);
}
render() {
<button onClick={this.handleClick('Parameter')}></button>
}
@sanketmeghani
sanketmeghani / event-handlers-with-parameters-bind-constructor.js
Last active December 1, 2017 08:36
React event handler with parameters using bind in constructor
class MyComponent extends React.Component {
constructor() {
super();
this.handleClick = this.handleClick.bind(this, 'Parameter');
}
handleClick(param, e) {
console.log('Parameter', param);
console.log('Event', e);
@sanketmeghani
sanketmeghani / math.js
Last active November 26, 2017 09:37
Example to demonstrate .load command
const add = (a, b) => a + b;
const multiply = (a, b) => a * b;
@sanketmeghani
sanketmeghani / simple-generator-function.js
Last active October 21, 2017 12:01
ES6 Generator Function
function* myFirstGenerator(a) {
console.log('Before yielding');
let b = 5 + (yield(a + 5));
console.log('After yielding');
return b;
}
@sanketmeghani
sanketmeghani / auto-semicolon-insertion.js
Created October 1, 2017 08:13
Error due to automatic semicolon insertion
const sum = (a, b) => {
return
{
result: a + b
}
}
const result = sum(1, 3)
console.log(result)
@sanketmeghani
sanketmeghani / no-auto-semicolon-insertion.js
Created October 1, 2017 07:50
Error due to no semicolon insertion
const a = 5
const b = 10
const c = a + b
[1, 2, 3].forEach((e) => console.log(e))
@sanketmeghani
sanketmeghani / rule3-semicolon-insertion.js
Created September 3, 2017 10:48
Automatic semicolon insertion as per rule #3
let myFunction = () => {
return;
}
const result = myFunction()
@sanketmeghani
sanketmeghani / automatic-seimicolon-insertion.js
Last active September 3, 2017 10:45
Explain automatic semicolon insertion
let myFunction = () => {
return
}
const result = myFunction()
@sanketmeghani
sanketmeghani / rule2-semicolon-insertion.js
Last active September 3, 2017 10:01
Semicolon insertion as per rule#2
let a = 10;
let b = true;
if(b) {
console.log('B is truthy');
}
console.log('A is ', a);
@sanketmeghani
sanketmeghani / rule1-2-semicolon-insertion.js
Created September 3, 2017 09:59
Semicolon insertion as per rule #1 subrule #2
let a = 10;
let b = true;
if(b) {
console.log('B is truthy');
}
console.log('A is ', a)