hacklone / arraync Goto Github PK
View Code? Open in Web Editor NEWAsync Array methods polyfills
License: MIT License
Async Array methods polyfills
License: MIT License
Correct me if I'm wrong, but as far as I can tell, there is no proposal for adding async functions to the array prototype, is there? If that's the case as I suspect, calling this library a polyfill is misleading. Also, editing the prototype of built-in types (such as the Array object) is highly discouraged these days as it risks clashes with future standards and other libraries. I suggest you change your library so it uses a new custom array type instead of adding extra methods to the prototype of the native Array. Here's an example using the ES2015 class syntax:
class AsyncArray extends Array {
constructor(…args) { super(…args); } // Apparently, this super call is necessary for built-in types
// Your extra async functions
}
This is my code -
'use strict';
const arraync = require('arraync');
function greaterThan3(num){
return new Promise(function(resolve, reject){
setTimeout(function(){
resolve(num > 3);
}, 1000);
});
}
var numbers = [1,2,3,4,5];
(async()=>{
const ans = await numbers.filterAsync(await greaterThan3Async);
console.log(ans);
})();
I'm trying to filter the array using an async function but this is what I get as output -
[ false, false, false, true, true ]
Also I get this same output when I use mapAsync
instead of filterAsync
.
How do I get the output -
[4, 5]
When I import the code using import 'arraync'
in typescript, it permanently adds all async array function names to any array props resulting in the following when I try to iterate an array using a for...in-loop in js:
var a = [1,2,3]; for(var item in a) console.log(item);
This causes a lot of problems for me, because accessing elements using the index is always broken. Is there a quick fix for this without searching the whole transpiled code? ;)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.