ES6 Chapter 1

  • Transpiling
    • [?] backwards compatibility OR rapid evolvement
    • [Answer] transformation compiling: to transform your ES6 code into equivalent (or close) matches that work in ES5 environments. (transformations how/when linting, minification, etc)
    • [Example] For example, consider shorthand property definitions

                var foo = [1,2,3];
                var obj = {
                    foo 	// means `foo: foo`
                };
                obj.foo;
                // [1,2,3]
      
                -------------------------------
                // transpiles:
      
                var foo = [1,2,3];
                var obj = {
                    foo: foo
                };
                obj.foo;
                // [1,2,3]
      

Not all new ES6 features need a transpiler. Polyfills (aka shims) are a pattern for defining equivalent behavior from a newer environment into an older environment.

				// strict equality of two values
				// without the nuanced exceptions that === has for NaN and -0 values
				if (!Object.is) {
					Object.is = function(v1, v2) {
					
					// test for `-0`
					if (v1 === 0 && v2 === 0) {
						return 1 / v1 === 1 / v2;
					}
					
					// test for `NaN`
					if (v1 !== v1) {
						return v2 !== v2;
					}
					
					// everything else
						return v1 === v2;
					};
				}