Arrow Function in Object Literal [duplicate]

Note that the Babel translation is assuming strict mode, but your result with window indicates you’re running your code in loose mode. If you tell Babel to assume loose mode, its transpilation is different: var _this = this; // ** var arrowObject = { name: ‘arrowObject’, printName: function printName() { console.log(_this); // ** } }; … Read more

How can I differentiate an object literal from other Javascript objects?

How can I tell the difference between an object literal and any other Javascript object (e.g. a DOM node, a Date object, etc.)? The short answer is you can’t. An object literal is something like: var objLiteral = {foo: ‘foo’, bar: ‘bar’}; whereas the same object created using the Object constructor might be: var obj … Read more

Object literal vs constructor+prototype

There is a (fundamental, in my opinion) difference between object literals and functions, the “private” variables. Since an object can’t be instantiated(because it is already an instance of Object) it has no possibility to have its own (new) scope. It is a base concept of advanced JS programming. Having a new scope allows you to … Read more

What is the call signature of an object literal type and how can they be used with generic types?

Functions can have properties, that’s what the object literal syntax is for: it allows to define a call signature and additional properties. Your two examples are equivalent because the second doesn’t define additional properties on the object literal. You can read more on that in the section on hybrid types. Additionally, the object literal allows … Read more