Questions tagged [javascript]
JavaScript (not to be confused with Java) is a high-level, dynamic, multi-paradigm, weakly-typed language used for both client-side and server-side scripting. Use this tag for questions regarding common implementations of ECMAScript, JavaScript, JScript, etc. JS does not typically refer to its ECMA-cousin, ActionScript.
2,127 questions
-4
votes
3
answers
253
views
Optimizing a "Transfer-Encoding: chunked" parser [closed]
I have written a parser for Transfer-Encoding: chunked requests over HTTP/1.1. Now I'm working on optimizing the code. This is the specification 7.1. Chunked Transfer Coding.
The first optimization ...
3
votes
3
answers
233
views
Best Practices for Implementing a Heartbeat Feature in a Laravel App to Track Offline Status
I'm trying to implement a heartbeat feature for offline tracking that just sends an offline message to the server once the web browser app (Laravel-based) is offline. Ideally it will ping the app's ...
3
votes
3
answers
193
views
Why does the collection library for Dart use a bit mask for hashing collections?
I was implementing a hashing function for a class and I took a minute to look at the first-party collection package for Dart to see how they implemented their hashing function for collections. They ...
1
vote
4
answers
355
views
Synchronized Web Audio Playback on Multiple Smartphones Using Timestamped Chunks and Manual Time Shifting
Note: I am not super knowledgeable web javascript or streaming, but I have read this and this and this I am proposing an alternate idea and just trying to verify whether I have a sound starting point ...
2
votes
1
answer
515
views
Unit testing a Web Worker in JavaScript/TypeScript - Best Practice
I got assigned with writing unit tests for a class that instantiate a Worker inside in it's constructor. The code looks simmilar to this,
class SomeClass {
private _worker: Worker;
constructor(...
0
votes
2
answers
271
views
How can I write more optimal code keeping Javascript "shapes"/"hidden classes" in mind?
All optimising Javascript runtimes use "shapes" (SpiderMonkey term) or "hidden classes" so that instead of objects being treated as the dictionaries or hashmaps they can instead be ...
4
votes
5
answers
625
views
Is changing the signature of a callback a breaking change?
In Javascript, should appending to the signature of a callback be considered a breaking change?
I.e. given an operation op(target, callback) should changing it from callback(item, index, array) to ...
-2
votes
1
answer
365
views
What is the best way to cache paginated data when any page can be moved to and page size is changeable?
I have a React Redux web app that fetches data from an Express/Node backend and MySQL database. I have a table of records that I fetch and store in redux as an array of objects, which I display as a ...
0
votes
1
answer
929
views
MongoDB schema: optional vs. nullable
If I have a schema that includes fields that may or may not be set, what is the best way to handle these fields? Should they be optional or instead nullable?
Here an example (Mongoose/NestJs)
@Schema()...
3
votes
3
answers
353
views
How to "pass through" data in a functional programming pipeline so that it's accessible later on in the pipeline
I am trying to refactor some JavaScript code to use functional programming principles.
I have some functions that I want to use in a series of maps.
const transformedData = rawData
.map(...
5
votes
3
answers
708
views
Are "pipelines" in functional programming bad for time complexity?
This question is not meant to be a critique of functional programming, but more hoping for resources and opinions.
I am refactoring some historically messy code so that it follows functional ...
1
vote
1
answer
637
views
Is it bad practice to export all the names from one module both as named exports and as a default export?
I like to export the names in my modules both as individual named exports and grouped together in a default export. Like this:
// mod.js
export function f() {}
export const x = true
export default {f,...
1
vote
1
answer
247
views
Refactoring to nested functions inside methods (JavaScript)
I've been reading Refactoring (2nd) by Martin Fowler. In the first chapter, he shows an example of refactoring a function where he extracts other functions from it and places them inside that function ...
1
vote
0
answers
227
views
What is a forged redirect? (in the context of javascript's fetch API)
I'm trying to make sense of the docs located at:
https://developer.mozilla.org/en-US/docs/Web/API/Response/redirected
It says
Note: Relying on redirected to filter out redirects makes it easy for
a ...
0
votes
2
answers
254
views
Is circular referencing required in this situation?
class ItemList {
constructor() {
this.list = [];//list holds many instances of Item Class
}
removeItem(id) {
//...search for item in this.list, remove it
}
}
class Item {
...
0
votes
1
answer
572
views
HTTP redirect vs JS redirect
I have a Svelte web app exclusively for internal use, so there is no main landing page or registration, as accounts need to be created by the admin. Since the main page has no function as an ...
1
vote
2
answers
366
views
Why did TC39 name JavaScript's array predicate functions `some` and `every` instead of `any` and `all`?
Python, Ruby, Rust, Haskell, Kotlin, C#, C++, Perl, MATLAB, SQL, and R all call their respective array predicate checking functions any and all.
Is there any record of why JavaScript's designers ...
1
vote
1
answer
307
views
Is module scoped initialisation considered a bad practice?
A module app.js includes another module service.js. The service.js module/file contains some functions but also does some module scoped initialisations(registry variable).
// service.js
const ...
0
votes
2
answers
492
views
Local development for TypeScript library organized as mono repo with Lerna
I currently am developing a TypeScript shared library. The library needs to be imported in sections to minimize the imported bundle size, so I broke it up into packages with a monorepo with Lerna. ...
1
vote
2
answers
152
views
JavaScript: Change prototype chain to morph objects from a deserialized JSON to business objects
This post assumes, that dtos on the UI side (SPA) could be viewed as business objects in almost all cases - except that the business logic is missing. I'm fully aware that a dtos first responsibility ...
0
votes
2
answers
545
views
ECMAScript Primitives: Immutability vs Value Type
Coming from languages like C++, Java or PHP I've learned that there are Value Types and Reference Types. Value Types store values directly in the variable (in a box / memory location). Whereas ...
0
votes
2
answers
218
views
ECMAScript specification of primitives and objects
When reading through the ECMAScript specification, I noticed, it actually never mentions concepts like "pass by value" or "pass by reference".
When looking at the assignment ...
-1
votes
1
answer
117
views
"Select All" in Table is now sending too much data to Server via API - Alternative Ways to Send to Server?
Outline of the current architecture of our web app outlining the issue I'm seeing
Client-side app is React, talking to a server running the Play! framework via an API.
On the page is a table that ...
0
votes
2
answers
454
views
Extensive use of global variables in js codebase?
I've been tasked with refactoring/simplifying the architecture of a (relatively) large node.js codebase and it makes ample use of global variables. I don't have much experience with javascript so just ...
1
vote
3
answers
239
views
How can I mix this grid to guarantee it being solvable in X minimum steps?
Note: This question is not about this particular instance of this grid with these exact words, but about any combination of words.
I am programming a puzzle game where you have to arrange a grid of ...