- use implicit labels instead of explicit labels
<!-- instead of explicit labels -->
<label for="formField">
<input id="formField" type="text" />
<!-- use of implicit labels -->
const autoprefixer = require('autoprefixer'); | |
const path = require('path'); | |
const webpack = require('webpack'); | |
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
const WebpackMd5Hash = require('webpack-md5-hash'); | |
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; | |
const BundleTracker = require('webpack-bundle-tracker'); | |
const ENV_VARS = { |
/* preferred way */ | |
handleClick={() => self.handleClick(index)} | |
//(or) | |
handleClick={e => self.handleClick(e, index)} | |
| |
/* current way */ | |
handleClick={this.handleClick.bind(this, index)} | |
//(or) | |
handleClick={this.handleClick.bind(null, index)} |
/* general way of writing a this bound method */ | |
class SampleComponent extends React.Component { | |
method = () => { | |
let props = this.props; // props can be accessed | |
} | |
} | |
| |
/* binding namespaced methods */ | |
| |
// Doesnt Work |
/** | |
* problem:: there is no way to know if a setInterval is cleared or still running. | |
* with the following utility function you can create a trackable setInterval. | |
* http://jsbin.com/dakewamihi/edit?js,console | |
*/ | |
/* definition */ | |
function setTrackableSetInterval(logicFn, delay, trackerObj) { | |
var trackerIndex = 0; |
/** | |
* memoize(fn[, options]) -> returns a new function which memoizes return values for given args. | |
* Arguments: | |
* 1. fn: -> function to be memoized. (pass function's promise if it is async). | |
* 2. options: { | |
* isAsync -> (boolean), if function to be memoized is async. | |
* cacheLimit -> (integer), max no. of results that can be stored in cache. | |
* } | |
*/ | |
// generally for in loops are used to save a non-referenced copy/snapshot of an array. this is a far simpler method to acheive the same | |
var arr = [1, 2, 3]; | |
// referenced copy of an array. | |
var arr_ref_copy = arr; | |
// non-referenced copy or snapshot of an array. | |
var arr_snapshot = arr.slice(0); |
function literallyEqual(value1, value2) { | |
var _fn = literallyEqual, | |
result = 1; | |
_fn.propLength = {}; | |
// getLength method is used to get simplify equality condition from (a subsetOf b && b subsetOf a) to (a subsetOf b && a.length = b.length). | |
_fn.getLength = function (object) { | |
if(Object.hasOwnProperty("keys")) return Object.keys(object).length; | |
// fallback for Object.keys. | |
var _len = 0, _key; | |
for (_key in object) { _len++; } |
/* Instead of | |
interval(); | |
setInterval(interval, 1000); | |
*/ | |
// -1. Invocation function already defined. | |
// Never use this even if it looks awesome implicit eval is slow because of an additional parse step. | |
function interval(){ | |
console.log("Invoked"); | |
} |