ecmascript-5

Compare array objects and show difference

北城以北 提交于 2019-12-31 03:24:08
问题 I have two arrays which I want to compare and check if there is an deleted item in one of these arrays. If there is show me the difference (deleted item) Here is the code below how I would like to achieve this: var completedList = [{id:1},{id:2},{id:3},{id:4},{id:7},{id:8}]; var invalidList = [{id:3},{id:4},{id:5},{id:6}]; // filter the items from the invalid list, out of the complete list var validList = completedList.map((item) => { console.log(item.id) return item.id; //console.log

Is it possible to determine if an object created with Object.create inherits from Array in JavaScript?

萝らか妹 提交于 2019-12-30 09:00:15
问题 Identifying which objects are which is complicated in JavaScript, and figuring out which objects are arrays has something of a hacky solution. Fortunately, it manages to work in both of the following cases: Object.prototype.toString.call([]); // [object Array] Object.prototype.toString.call(new Array()); // [object Array] Great, no [object Object] in sight! Sadly, this method still manages to fail with this: var arr = Object.create(Array.prototype); Object.prototype.toString.call(arr); //

Javascript conditional regular expression if-then-else

廉价感情. 提交于 2019-12-28 15:04:34
问题 I'm trying to limit the entries to a specific format. If the entry has 5500 or 5100 such as 01\01-5500-000-00 then I want to have this: ^[0-9]{2,}\\[0-9]{2}\-[0-9]{4}\-[0-9]{3}\-$ But if the entry has anything other than 5500 or 5100 I want to have this: ^[0-9]{2,}\\[0-9]{2}\-[0-9]{4}\-[0-9]{3}\-[0-9]{2}$ How can this be accomplished with the if then else idea? 回答1: Conditional regex syntax is not supported by JavaScript regex engine, but it can be worked around with a non-capturing group

Why and how does ([![]]+[][[]])[+!+[]+[+[]]] evaluate to the letter “i”? [duplicate]

旧街凉风 提交于 2019-12-27 17:29:41
问题 This question already has answers here : Why does ++[[]][+[]]+[+[]] return the string “10”? (9 answers) (![]+[])[+[]]… Explain why this works (1 answer) Closed 6 years ago . While reading this article posted on dzone I found a snippet of JavaScript originally posted on Twitter by Marcus Lagergren. The following code apparently prints the string "fail" (![]+[])[+[]]+(![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]; This involves implicit type casting and I'm trying to understand

What is the `filter` call for in this string split operation?

孤者浪人 提交于 2019-12-25 17:16:08
问题 I have a line of legacy code to split a string on semi-colons: var adds = emailString.split(/;+/).filter(Boolean); What could the filter(Boolean) part do? 回答1: filter(Boolean) will only keep the truthy values in the array. filter expects a callback function, by providing Boolean as reference, it'll be called as Boolean(e) for each element e in the array and the result of the operation will be returned to filter . If the returned value is true the element e will be kept in array, otherwise it

Unexpected token illegal javascript/meteor

别等时光非礼了梦想. 提交于 2019-12-25 17:15:24
问题 When I put this array into my Server/servermethods.js I get this error: server/serverMethods.js:4:1783: Unexpected token ILLEGAL I'm using meteor, but I think this is some sort of javascript error. I've checked, it's not missing commas or apostrophes. var RedemtionCodes =['27GP','2DNW','2DPH','2SE7’,‘2U29’,‘2V5Q’,‘2WNY’,‘2XU6’,‘35W4’,‘3BC4’,‘3H3P’,‘3LQG’,‘3NHL’,‘3T8Y’,‘3UXV’,‘3ZG7’,‘48RD’,‘48WS’,‘4AYE’,‘4E6V’,‘4J36’,‘4KMM’,‘4QNA’,‘4RHV’,‘4RSV’,’4WZK’,’536G’,’567K’,’58EN’,’58NC’,’5B2Z’,’5DU8’,

Arrow function from meteor build is crashing heroku deploy

天大地大妈咪最大 提交于 2019-12-24 01:27:16
问题 I have deployed a js application on heroku that uses meteor. The build works on localhost but fails on the heroku server. I checked the logs and found this: .js:312:12) 2017-03-18T03:29:07.070711+00:00 app[web.1]: const unicodeNormalizePath = (path) => { 2017-03-18T03:29:07.074825+00:00 app[web.1]: at Module.require (module.js:364:17) 2017-03-18T03:29:07.074821+00:00 app[web.1]: SyntaxError: Unexpected token > 2017-03-18T03:29:07.074824+00:00 app[web.1]: at Module.load (module.js:356:32) 2017

Laravel Mix not transpiling vendor.js to es5

拥有回忆 提交于 2019-12-24 00:33:42
问题 Laravel Mix does not seem to transpile vendor.js and manifest.js to ES5. It fails on iPhone Safari and IE 11. IE DevTools shows these errors: And it appears that it still has ES6 features: The other files seem to transpile such as app.js and the chunks. Here's my webpack.mix.js let mix = require('laravel-mix'); let options = { processCssUrls: false, } let config = { output: { chunkFilename: 'assets/js/chunks/[name].js', publicPath: '/' } } if (mix.inProduction()) { config.output.chunkFilename

Using Modules in the Browser (without WebPack)

谁都会走 提交于 2019-12-23 08:58:45
问题 I'm grokking my way through ES6 and I ran into Modules (nice!) and in learning, I am trying to see if I can use them in the browser without WebPack (which I haven't learned yet). So, I have the following files/folder structure in my JS directory js - lib (for complied es6 via Babel) - mods (compiled modules) - module.js (compiled via Babel) - app.js (imports modules, attached to index.html) - src (for "raw" es6) - mods (es6 modules) - module.js (es6 module) - app.js (imports modules) In js

Using Babel with a single output file and ES6 modules

回眸只為那壹抹淺笑 提交于 2019-12-23 08:02:34
问题 Here's my gulp task to compile my ES6 code into a single ES5 file. I use classes and modules ( import , export ) in ES6. gulp.src(paths.scripts) .pipe(sourcemaps.init()) .pipe(babel({ presets: ['es2015'] })) .pipe(concat('all.js')) .pipe(sourcemaps.write('.')) .pipe(gulp.dest('./www/js')); However, because Babel compiles ES6 import directives into require commands, and require will attempt to request a file, the request files are failing because all the ES5 code is concatted into one file,