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 ...
-4
votes
2
answers
247
views
How to design a Transfer-Encoding: chunked parser of Uint8Array's in JavaScript? [closed]
I'm working on implementing parsing a series of Uint8Arrays that contain Transfer-Encoding: chunked data sent from the client using WHATWG Fetch over a single connection.
For example, writing 1 MB ...
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 ...
2
votes
1
answer
105
views
How can I generate visualizations in JavaScript using data and packages from R?
I have a tumor dataset in R that is a Seurat object. I am working on a project to develop a new visualization tool for single-cell RNA-seq data. I want to develop the visualization using JavaScript, ...
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 ...
5
votes
2
answers
1k
views
Performance consideration for cascading style sheet implementation
I have the plan for an UI component hierarchy. Each UI component contains zero or more children UI components, and each UI component may set an optional theme.
A theme is responsible for skinning a ...
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
80
views
Advice on how to ensure input only comes from my website component?
I have a website with an online keyboard. Essentially people can type on this online keyboard and send messages worldwide.
My problem is users can easily intercept the POST network call to the backend ...
2
votes
1
answer
514
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(...
-4
votes
1
answer
103
views
How to develop portable HTTP clients across js/ts web frameworks? [closed]
Related: Best practice for interoperable TypeScript→JavaScript? - Frameworks, browser extensions
Angular, React, Vue, Svelte &etc. exist and are popular. Some use rxjs to flow from HTTP response, ...
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 ...
0
votes
1
answer
144
views
Where to store important information needed for the UI in Vue? (Name etc)
I am writing an application using a C# backend and a Vue frontend, and I am a bit sceptical about where is best to store information about the user that is currently logged in.
There are a few posts ...
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 ...
0
votes
0
answers
80
views
approximating a shape with a line
I have an image that has been converted to an svg.
The conversion looks fine, but it has prefered to use fill instead of stroke.
This in itself is not a bad thing in terms of converting a raster image ...
-2
votes
1
answer
363
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 ...
-2
votes
1
answer
116
views
Advice on data structure for an analysis and visualisation tool (javascript)
I am writing a browser-based tool to manipulate and visualise data (with D3.js). Currently, I store data in a JSON format, where each table is an object and columns are arrays. eg:
{
"data&...
0
votes
1
answer
924
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()...
0
votes
3
answers
261
views
How to filter "locally and remotely" in functional programming
My example applies to reading and deleting files (I/O), but this is probably a common scenario (eg, keeping local and global state in sync in functional programming).
I am reading in files from a ...
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(...
2
votes
1
answer
455
views
How do I properly organize JavaScript files for web development?
I am fairly new to web development and have been trying to figure out the best way to organize my JavaScript files for the front-end.
The first approach I started with was "one JavaScript file ...
5
votes
3
answers
707
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 ...
2
votes
1
answer
127
views
Concrete implementation of MVP with "dumb" view
I recently started designing my first MVP-app. I like the idea of having a "dumb" view to be able to cover as much of the code with unit tests.
The app I build will be an app to create ...
1
vote
1
answer
635
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,...
0
votes
1
answer
782
views
Best practice - depending on object key iteration order?
In Javascript, the iteration order of an Object is enforced since ES2020 (or before, depending...).
However, is it a good idea (i.e. best practice) to depend on this?
I'm currently working on a ...
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 ...
2
votes
3
answers
565
views
Critical Infrastructure Language Selection
I took over a development team working on life-safety critical software earlier in the year. The product has been in development for about 8 years, but the current team has only been working on the ...
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 ...
1
vote
1
answer
561
views
Using JS and CSS parent selector to replace media queries: is it a good practice?
I really don't like media queries in CSS - they have limitations, and on top of that they make the code a lot more confusing.
In addition, the restrictions are so strong that when using CSS ...
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
625
views
Array structure for nested grouping (JavaScript)
I am currently struggling with how to solve nested grouping of data.
The initial structure is given and my grouped structure below as well as my approach can be adjusted.
My idea was to have the array ...
0
votes
1
answer
571
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 ...
3
votes
1
answer
293
views
Is it good practice to always use "use strict" in modern web apps? [closed]
I'm learning JavaScript and just came across "use strict". It sounds like to me it should always be in play but me being a beginner I was wondering if there are scenarios/environments when ...
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 ...
0
votes
1
answer
184
views
Why is `WeakSet` great for tracking circular references?
In MDN article on WeakSets, an example is given for using weak sets to avoid infinite recursion on circular references:
// Execute a callback on everything stored inside an object
function ...
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 ...
1
vote
2
answers
322
views
Variable assignment in ECMAScript specification in detail
I am trying to wrap my head around what the ECMAScript specification suggests about variable assignment.
Introduction:
Coming from Java, this is pretty straight forward. Variables get stored at a ...
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
4k
views
How to represent the absent of a field value in json response?
I am a react developer and writing the client on pure JS. I have sometimes missions to received data from server and send data to server. Now between the client team and backend rough discussion ...
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
748
views
synchronize HTML5 or JavaScript video to realtime?
I will have multiple cellphones playing videos in an art gallery. The video content must be synced to the lights, which are synced to the real-world clock. As in, at 1:00pm the lights go out, 1:15 ...
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 ...
26
votes
8
answers
11k
views
Is it okay to hard-code table and column names in queries?
I've got a backend running on Node that executes queries on a PostgreSQL database. For these queries, table and column names are imported from a .env file, for example:
const ID = process.env.ID_COL;
...
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
vote
3
answers
2k
views
Best strategy to push client-side updates to server?
I'm just starting to build a web app using React.js, Next.js, Prisma, & PostgreSQL. In this web app, users can create "projects", which are represented by 10-15 rows in the database. ...
-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 ...
3
votes
1
answer
330
views
Do the maintainers of JavaScript remove features?
Really dumb question. I really like the new feature called "optional chaining" in JavaScript, and it's used in quite a few places in my front end code. However, I am concerned that whoever ...
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
1
answer
2k
views
What are the benefits of keeping npm packages up-to-date? [closed]
The company I work for is maintaining and developing a web application that uses many Node.js packages. A lot of these packages are really outdated. I can intuitively understand that it is good to ...
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 ...
1
vote
1
answer
411
views
Can I separate methods into different classes by passing in constructor properties from one class to another?
I am making a game of monopoly. Inside my game I have a Board class. The Board class has an array which contains 40 squares. Each square is a different class e.g. ChanceSquare, PropertySquare ...