ecmascript-5

Why 42.toString() fails in JS?

情到浓时终转凉″ 提交于 2020-01-22 12:30:07
问题 Disclaimer Guys, I DO aware of Why does 10..toString() work, but 10.toString() does not? question existence, but the thing is that it doesn't provide the formal explanation. The specification's interpretation of the . character in that particular position is that it will be a decimal. This is defined by the numeric literal syntax of ECMAScript. Without reference to a standard isn't trustable enough The question body I subconsciously understand that 42..toString() is treated by a parser as a

Return from a method in which forEach() array method was called. JavaScript

梦想的初衷 提交于 2020-01-22 03:20:15
问题 I am using forEach() method called from an array in JavaScript. When I write return; somewhere inside the method which is called for every element in array I return out from the method which was called for a specific element and that is all. But what I actually want is to return out from the method in which array called forEach(). Here is the code: function addToCart(pizza, size) { Cart.forEach(function(cartItem) { if(pizzaAndSizeAreTheSame(cartItem, pizza, size)) { cartItem.quantity++;

Problem with Angular Element support in chrome and IE11 simultaneously

微笑、不失礼 提交于 2020-01-21 08:31:04
问题 I have been playing around with Angular Elements and trying to achieve the best browser compatibility possible. However I seem to have hit a dead end, since when I add an IE polyfill for Shadow DOM, it breaks the Element in chrome. Initially I had the error 'Failed to construct HTML element', so I changed the 'target' in my tsconfig.json to es2015/es6. tsconfig.json { "compileOnSave": false, "compilerOptions": { "baseUrl": "./", "outDir": "./dist/out-tsc", "sourceMap": true, "declaration":

Is there a polyfill for es6 arrow function?

瘦欲@ 提交于 2020-01-21 02:38:05
问题 Is there a polyfill for es6 arrow function? the following code throws syntax error exception in IE, is there a polyfill to make IE support arrow functions? var myFunc = ()=>{ alert('es6'); } myFunc(); Note : I don't want to use any transpiler . Thanks in advance 回答1: A polyfill can add or fix missing built-in classes, functions, objects... but it cannot modify a compiler's accepted syntax. 回答2: There is no polyfill for arrow functions. It is a syntax error to write the code you have unless

Keystone+React: 'import' and 'export' may appear only with 'sourceType: module'

送分小仙女□ 提交于 2020-01-17 03:58:26
问题 After updating the project dependencies I started facing the error. Browserify has problem parsing my JS code, which is written in ES6. Browserify seems to expect ES5. I don't understand, why the sourceType: module seems to be the issue here. Source: var babelify = require('babelify'); var browserify = require('browserify-middleware'); var keystone = require('keystone'); var importRoutes = keystone.importer(__dirname); // Setup Route Bindings exports = module.exports = function(app) { app.use

Is there a polyfill for es6 arrow function?

依然范特西╮ 提交于 2020-01-16 08:05:51
问题 Is there a polyfill for es6 arrow function? the following code throws syntax error exception in IE, is there a polyfill to make IE support arrow functions? var myFunc = ()=>{ alert('es6'); } myFunc(); Note : I don't want to use any transpiler . Thanks in advance 回答1: A polyfill can add or fix missing built-in classes, functions, objects... but it cannot modify a compiler's accepted syntax. 回答2: There is no polyfill for arrow functions. It is a syntax error to write the code you have unless

How to implement a negative LOOKAHEAD check for a token in JavaCC?

旧时模样 提交于 2020-01-15 19:16:42
问题 I currently implementing a JavaScript/ECMAScript 5.1 parser with JavaCC. I recently learned about LOOKAHEAD s which are handy here as the grammar is not fully LL(1). One of the things I see in the ECMAScript grammar is "negative lookahead check", like in the following ExpressionStatement production: ExpressionStatement : [lookahead ∉ {{, function}] Expression ; So I'll probably need something like LOOKAHEAD(!("{" | "function")) but it does not work in this syntax. My question is, how could I

using try catch on error generated by asynchronous callback function

ⅰ亾dé卋堺 提交于 2020-01-14 22:42:28
问题 I am trying to catch an error caused by an async javascript callback function, try{ setTimeout(()=>{ throw err console.log("after throw") }, 1000) }catch(e){ console.log("caught"); } But as many of you may know catch block is never executed, so what exactly is happening here ? I know I can achieve similar thing using promises and async/await, async foo(){ try{ await setTimeoutPromise(1000); }catch(e){ alert("caught"); } } 回答1: When you use setTimeout, the callback gets pushed into the event

using try catch on error generated by asynchronous callback function

爷,独闯天下 提交于 2020-01-14 22:42:27
问题 I am trying to catch an error caused by an async javascript callback function, try{ setTimeout(()=>{ throw err console.log("after throw") }, 1000) }catch(e){ console.log("caught"); } But as many of you may know catch block is never executed, so what exactly is happening here ? I know I can achieve similar thing using promises and async/await, async foo(){ try{ await setTimeoutPromise(1000); }catch(e){ alert("caught"); } } 回答1: When you use setTimeout, the callback gets pushed into the event

Why does Chrome & FireFox console print undefined?

泄露秘密 提交于 2020-01-14 14:39:13
问题 Take this simple Test object and paste it into the console, you'll see that it says undefined . The object is working because it also prints 123 , but what is the undefined about. Test: var Test = new (function(){ return { get testing(){ return "123"; } } }); console.log(Test.testing); Console Output: 123 undefined 回答1: That is the return value of console.log . Try console.log(1); which gives 1 undefined However, if you type just Test.testing that gives only "123" 回答2: undefined is the return