Search the Community
Showing results for tags 'ES6'.
-
I'm asking about the 'this' binding in the arrow function of an object created by object literal syntax vs ES6 class syntax. Case 1: Object literal const obj = { method: ()=>{ console.log(this) } } obj.method(); Output Window {window: Window, self: Window, document: document, name: "result", location: Location, …} Case 2: ES6 class syntax class obj{ method = ()=>{ console.log(this); } } (new obj).method(); Output obj {method: ƒ} I know arrow functions do not bind their own this, instead, they inherit the one from the parent scope then Why the result is different on the above two cases. Thanks in advance.
-
Dear all, Are JS tutorials of W3Schools written using the latest version of JS, known as ES6 (ECMAScript 6)?