Why is there no forEach method on Object in ECMAScript 5?

Well, it’s pretty easy to rig up yourself. Why further pollute the prototypes? Object.keys(obj).forEach(function(key) { var value = obj[key]; }); I think a big reason is that the powers that be want to avoid adding built in properties to Object. Objects are the building blocks of everything in Javascript, but are also the generic key/value … Read more

JavaScript: Can ECMAScript 5’s Strict Mode (“use strict”) be enabled using single quotes (‘use strict’)?

For you, without using a browser that supports strict mode: A Use Strict Directive is an ExpressionStatement in a Directive Prologue whose StringLiteral is either the exact character sequences “use strict” or ‘use strict’. A Use Strict Directive may not contain an EscapeSequence or LineContinuation.

How do I perform an export that is compatible with ES5 and ES6?

As far as writing an export that is compatible for both ES5 and ES6, Babel already takes care of that for you. (As communicated in the comments to your question. I’m only clarifying for those who got lost in the dialog.) module.exports = MyClass will work with both var MyClass = require(‘mymodule’) and import MyClass … Read more

Mixed default and named exports in Node with ES5 syntax

You want to assign the value of module.exports to be your default function, and then put all the named exports as properties on that function. const defaultFunction = () => { console.log(‘default!’); }; const namedFunction1 = () => { console.log(‘1!’); }; const namedFunction2 = () => { console.log(‘2!’); }; const myModule = module.exports = defaultFunction; … Read more

In ECMAScript5, what’s the scope of “use strict”?

“use strict” applies only to function or program scope. So if you have fileA.js with “use strict” at the top, fileA.js executes in strict mode, and all functions defined in it will do the same when called. But fileB.js is a separate program, so the “use strict” from fileA.js doesn’t apply to it — and … Read more

`new Object` vs `Object` in the ECMAScript spec

Object(window) will never clone window but new Object(window) might. All current — potentially all known — implementations just return the same reference, although the spec allows for implementation-defined behavior. The steps for 15.2.1.1 say: If value is null, undefined or not supplied, create and return a new Object object exactly as if the standard built-in … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)