Update Polyfills.
- Update load/array.js to include flat and flatmap methods
- Add load/object.js to include various Object methods
- Added .vscode/settings.json to avoid mangling existing formatting
Merge request reports
Activity
added 1 commit
- edc8eb80 - Object.assign should coerce to an object type if not an object already.
@Deuce @rswindell @echicken thoughts? There's already existing Array polyfills, wanted to add a couple missing methods as well as some Object methods missing... Would like to followup with a couple bits on strings as well.
Writing some modules that are using these, and was going to release them in the next week or so for others to use.
Edited by Michael J. Ryan- .vscode/settings.json 0 → 100644
1 /* $Id: array.js,v 1.1 2019/07/22 20:51:52 echicken Exp $ */ 2 1 /** 3 2 * Polyfills for newer Array methods 4 3 * Lifted from MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array 5 * changed this line in version 5 of the diff
327 328 if (sameValueZero(o[k], searchElement)) return true; 328 329 k++; 329 330 } 330 331 331 332 // 8. Return false 332 333 return false; 333 334 } 334 335 }); 335 336 } 337 Is anything actually using this library currently? Does it need these addition methods?
In general, I'm not a fan of adding stuff "just because". It becomes a maintenance headache. Does someone actually need this stuff and have an immediate use for it (in Synchronet) or is just for completionism?
If there's a need/use and it doesn't break anything else, I'm not opposed.
I think I'm using exec/load/array.js for a few things in webv4. It's just a bunch of useful shorthand/convenience stuff that JS devs are accustomed to having available (and for that reason, it's nice to have it here).
That said, I'll be using 'for' loops a lot more often now, when performance matters. Recent adventures in optimization have shown me that there's a lot of time to be saved that way - though it's not always worth worrying about.
@echicken yeah, for loops are often faster, though I still prefer map/reduce syntax... if we had fat-arrow functions, it'd be much cleaner syntax wise.
- .vscode/settings.json 0 → 100644
1 { 2 "editor.formatOnSave": false, 3 "editor.insertSpaces": false, 4 "files.associations": { 5 "*.ssjs": "javascript", 6 }, 7 "[c]": { 8 "editor.tabSize": 2, changed this line in version 3 of the diff
- Resolved by Michael J. Ryan
58 59 var len = toLength(items.length); 59 60 60 61 // 13. If IsConstructor(C) is true, then 61 // 13. a. Let A be the result of calling the [[Construct]] internal method changed this line in version 4 of the diff
295 296 value: function (searchElement, fromIndex) { 296 297 // 1. Let O be ? ToObject(this value). 297 298 if (this == null) throw new TypeError('"this" is null or not defined'); 298 changed this line in version 4 of the diff
295 296 value: function (searchElement, fromIndex) { 296 297 // 1. Let O be ? ToObject(this value). 297 298 if (this == null) throw new TypeError('"this" is null or not defined'); 298 299 299 300 var o = Object(this); 300 changed this line in version 4 of the diff
295 296 value: function (searchElement, fromIndex) { 296 297 // 1. Let O be ? ToObject(this value). 297 298 if (this == null) throw new TypeError('"this" is null or not defined'); 298 299 299 300 var o = Object(this); 300 301 301 302 // 2. Let len be ? ToLength(? Get(O, "length")). 302 303 var len = o.length >>> 0; 303 changed this line in version 4 of the diff
299 299 300 var o = Object(this); 300 301 301 302 // 2. Let len be ? ToLength(? Get(O, "length")). 302 303 var len = o.length >>> 0; 303 304 304 305 // 3. If len is 0, return false. 305 306 if (len === 0) return false; 306 307 307 308 // 4. Let n be ? ToInteger(fromIndex). 308 309 // (If fromIndex is undefined, this step produces the value 0.) 309 310 var n = fromIndex | 0; 310 changed this line in version 4 of the diff
295 296 value: function (searchElement, fromIndex) { 296 297 // 1. Let O be ? ToObject(this value). 297 298 if (this == null) throw new TypeError('"this" is null or not defined'); 298 299 299 300 var o = Object(this); 300 301 301 302 // 2. Let len be ? ToLength(? Get(O, "length")). 302 303 var len = o.length >>> 0; 303 304 304 305 // 3. If len is 0, return false. 305 306 if (len === 0) return false; 306 changed this line in version 4 of the diff
304 305 // 3. If len is 0, return false. 305 306 if (len === 0) return false; 306 307 307 308 // 4. Let n be ? ToInteger(fromIndex). 308 309 // (If fromIndex is undefined, this step produces the value 0.) 309 310 var n = fromIndex | 0; 310 311 311 312 // 5. If n ≥ 0, then 312 313 // a. Let k be n. 313 314 // 6. Else n < 0, 314 315 // a. Let k be len + n. 315 316 // b. If k < 0, let k be 0. 316 317 var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); 317 changed this line in version 4 of the diff
327 328 if (sameValueZero(o[k], searchElement)) return true; 328 329 k++; 329 330 } 330 changed this line in version 4 of the diff
308 309 // (If fromIndex is undefined, this step produces the value 0.) 309 310 var n = fromIndex | 0; 310 311 311 312 // 5. If n ≥ 0, then 312 313 // a. Let k be n. 313 314 // 6. Else n < 0, 314 315 // a. Let k be len + n. 315 316 // b. If k < 0, let k be 0. 316 317 var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); 317 318 318 319 function sameValueZero(x, y) { 319 320 return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y)); 320 321 } 321 changed this line in version 4 of the diff
@rswindell in the future, in the "changes" tab, you can click the gears, and uncheck the show whitespace changes.